public class SpringConfigObjectResolver extends AbstractObjectResolver
Per Default the bean with id = key.replace('/', '.') will be returned. But you can configure a key "bean-ref" in the
Properties
-File for the given Object.
Example: The following code should return a DataSource
Object:
Settings4j.getObject("com/myCompany/myApp/MyDatasource");
In normal Cases the DataSource comes from the JNDI-Context (available in most Servlet Containers).
But in some environments there are no JNDI-Context (Commandline-Clients, UnitTests).
With Settings4j (default configuration) you can also place two Files into your Classpath:
"com/myCompany/myApp/MyDatasource"
: The File which defines the DataSource
"com/myCompany/myApp/MyDatasource.properties"
: Some Properties, like which ObjectResolver should be
use.
The File Content whould be the following:
Classpath File "com/myCompany/myApp/MyDatasource.properties":objectResolverKey=org.settings4j.objectresolver.SpringConfigObjectResolver bean-ref=SpringBeanReferneceId
Classpath File "com/myCompany/myApp/MyDatasource":<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <!-- HSQLDB --> <bean id="SpringBeanReferneceId" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"><value>org.hsqldb.jdbcDriver</value></property> <property name="url"><value>jdbc:hsqldb:mem:test</value></property> <property name="username"><value>sa</value></property> <property name="password"><value></value></property> </bean> </beans>
PROP_CACHED, PROP_OBJECT_RESOLVER_KEY
Constructor and Description |
---|
SpringConfigObjectResolver() |
Modifier and Type | Method and Description |
---|---|
protected Object |
contentToObject(String key,
Properties properties,
byte[] content,
ContentResolver contentResolver)
Method to convert the given content-File to an Object must be implemented by SubClasses.
|
addObjectResolver, getObject, getObjectProperties, getObjectResolverKey, getPropertySuffix, isCached, setCached, setPropertySuffix
protected Object contentToObject(String key, Properties properties, byte[] content, ContentResolver contentResolver)
contentToObject
in class AbstractObjectResolver
key
- The Original Key of the Objectproperties
- The Property-File which where Found under key + ".properties"content
- The byte[] Content to convert.contentResolver
- the contentResolver to get possible additional content Files.Copyright © 2008–2014. All rights reserved.