I am trying to access a protected data source from spring passing the initial context factory, provider url, principal, credentials.
I am using WLS 8.1.3 with a role condition saying that only the user "zadevl" (with the
correct credentials) can have access to all the resources in the container.
Following is excerpt from the spring config.xml
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryB ean" singleton="false">
<property name="resourceRef"><value>true</value></property>
<property name="java.naming.factory.initial"><value>weblogic .jndi.WLInitialContextFactory</value></property>
<property name="java.naming.provider.url"><value>t3://dfapt-ap02:7277</value></property>
<property name="jndiName"><value>jdbc/txamengineInputPool</value></property>
<property name="java.naming.security.principal"><value>zadev l</value></property>
<property name="java.naming.security.credentials"><value>pas sword</value></property>
</bean>
I am getting the following exception.
testGetProductCharacteristicsProductType(com.wlspo licy.spring.test.TestCharacteristicsService)org.sp ringframework.beans.factory.BeanDefinitionStoreExc eption: Error registering bean with name 'dataSource' defined in resource loaded through InputStream: Validation of bean definition with name failed; nested exception is org.springframework.beans.factory.support.BeanDefi nitionValidationException: FactoryBean must be defined as singleton - FactoryBeans themselves are not allowed to be prototypes
org.springframework.beans.factory.support.BeanDefi nitionValidationException: FactoryBean must be defined as singleton - FactoryBeans themselves are not allowed to be prototypes
at org.springframework.beans.factory.support.RootBean Definition.validate(RootBeanDefinition.java:151)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.registerBeanDefinition(DefaultL istableBeanFactory.java:323)
at org.springframework.beans.factory.support.BeanDefi nitionReaderUtils.registerBeanDefinition(BeanDefin itionReaderUtils.java:122)
at org.springframework.beans.factory.xml.DefaultXmlBe anDefinitionParser.registerBeanDefinitions(Default XmlBeanDefinitionParser.java:187)
at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.registerBeanDefinitions(XmlBeanDefinit ionReader.java:175)
at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:133)
at org.springframework.beans.factory.xml.XmlBeanFacto ry.<init>(XmlBeanFactory.java:88)
at org.springframework.beans.factory.xml.XmlBeanFacto ry.<init>(XmlBeanFactory.java:59)
at com.wlspolicy.spring.test.TestCharacteristicsServi ce.setUp(TestCharacteristicsService.java:39)
at com.wlspolicy.spring.test.TestCharacteristicsServi ce.main(TestCharacteristicsService.java:21)
To avoid this isngleton error I tried the following configuration
Following spring config.xml is same as above except for the attribute singleton="true".
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryB ean" singleton="true">
<property name="resourceRef"><value>true</value></property>
<property name="java.naming.factory.initial"><value>weblogic .jndi.WLInitialContextFactory</value></property>
<property name="java.naming.provider.url"><value>t3://dfapt-ap02:7277</value></property>
<property name="jndiName"><value>jdbc/txamengineInputPool</value></property>
<property name="java.naming.security.principal"><value>zadev l</value></property>
<property name="java.naming.security.credentials"><value>pas sword</value></property>
</bean>
Now I am getting the following exception saying that all the java.x.y.z properties are invalid.
testGetProductCharacteristicsProductType(com.wlspo licy.spring.test.TestCharacteristicsService)org.sp ringframework.beans.factory.BeanCreationException: Error creating bean with name 'charactericsDAO' defined in resource loaded through InputStream: Can't resolve reference to bean 'dataSource' while setting property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'dataSource' defined in resource loaded through InputStream: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'java.naming.factory.initial' of bean class [org.springframework.jndi.JndiObjectFactoryBean]: Nested property in path 'java.naming.factory.initial' does not exist; nested exception is org.springframework.beans.NotReadablePropertyExcep tion: Invalid property 'java' of bean class [org.springframework.jndi.JndiObjectFactoryBean]: Bean property 'java' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'dataSource' defined in resource loaded through InputStream: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'java.naming.factory.initial' of bean class [org.springframework.jndi.JndiObjectFactoryBean]: Nested property in path 'java.naming.factory.initial' does not exist; nested exception is org.springframework.beans.NotReadablePropertyExcep tion: Invalid property 'java' of bean class [org.springframework.jndi.JndiObjectFactoryBean]: Bean property 'java' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'java.naming.factory.initial' of bean class [org.springframework.jndi.JndiObjectFactoryBean]: Nested property in path 'java.naming.factory.initial' does not exist; nested exception is org.springframework.beans.NotReadablePropertyExcep tion: Invalid property 'java' of bean class [org.springframework.jndi.JndiObjectFactoryBean]: Bean property 'java' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
org.springframework.beans.NotReadablePropertyExcep tion: Invalid property 'java' of bean class [org.springframework.jndi.JndiObjectFactoryBean]: Bean property 'java' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
at org.springframework.beans.BeanWrapperImpl.getPrope rtyValue(BeanWrapperImpl.java:595)
at org.springframework.beans.BeanWrapperImpl.getNeste dBeanWrapper(BeanWrapperImpl.java:496)
at org.springframework.beans.BeanWrapperImpl.getBeanW rapperForPropertyPath(BeanWrapperImpl.java:474)
at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:677)
at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:826)
at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:853)
at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:842)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:874)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:688)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:325)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:260)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:221)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:145)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.resolveReference(Abstra ctAutowireCapableBeanFactory.java:980)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.resolveValueIfNecessary (AbstractAutowireCapableBeanFactory.java:918)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:859)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:688)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:325)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:260)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:221)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:145)
at com.wlspolicy.spring.test.LookupFactory.getCharact ericsDao(LookupFactory.java:63)
at com.wlspolicy.spring.test.TestCharacteristicsServi ce.setUp(TestCharacteristicsService.java:41)
at com.wlspolicy.spring.test.TestCharacteristicsServi ce.main(TestCharacteristicsService.java:21)
Is this the right way to access a protected data source or is there any other way.
Could you please provide me an example how to make this work.
I really appreciate your help.
Thanks a lot.
Raj.


Reply With Quote