Two Laptop Bag*
The moose likes Other Application Frameworks and the fly likes Spring jndi in context.xml / MyEclipse / Oracle / SJAS 9.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Spring jndi in context.xml / MyEclipse / Oracle / SJAS 9.1 " Watch "Spring jndi in context.xml / MyEclipse / Oracle / SJAS 9.1 " New topic
Author

Spring jndi in context.xml / MyEclipse / Oracle / SJAS 9.1

Ru Diaz
Greenhorn

Joined: Jan 08, 2009
Posts: 5
Hi Everyone,

Apologies in advance if this is the wrong thread to place this issue.

I wrote some code for a J2EE application that uses Hibernate and Spring. I created a dao and a
test for that dao. However, when I try to run the unit test for that dao, I get an error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appdataSource-direct' defined in URL [file:/C:/workspace/companyweb/WebRoot/WEB-INF/classes/app-model-context.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'jndiName' is required
Caused by: java.lang.IllegalArgumentException: Property 'jndiName' is required
at org.springframework.jndi.JndiObjectLocator.afterPropertiesSet(JndiObjectLocator.java:90)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:146)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1198)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1167)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:427)

and other similar lines.


My app-model-context.xml file is:

==========BEGIN =================================================

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
<!-- ======================== Database Definitions ======================== -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreResourceNotFound" value="true" />
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="searchSystemEnvironment" value="true" />
<property name="locations">
<list>
<value>classpath:app.properties</value>
</list>
</property>
</bean>

<bean id="appdataSource-direct"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${connection.pool.datasource.standard}" />
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="appdataSource-direct" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.bytecode.use_reflection_optimizer">false</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/company/app/dao/DClient.hbm.xml</value>
</list>
</property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributeSource" ref="transactionAttributeSource" />
</bean>

<bean id="transactionAttributeSource" class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource" />

<!-- ======================== Dao Definitions ======================== -->

<bean id="dClientDao" class="com.company.app.dao.DClientDao" singleton="true" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>

</beans>

==========END =================================================


My app.properties file is:

==========BEGIN =================================================

connection.pool.standard=appUserPool
connection.pool.datasource.standard=
connection.pool.admin=admin
connection.pool.datasource.admin=admin
app.database.name=appdb
app.database.server=cat
app.database.port=1508
app.report.server.host=
app.report.server.port=
app.driverclass=oracle.jdbc.driver.OracleDriver
app.url=jdbcracle:thin:@cat:1508:appdb
app.username=admin
app.password=password

==========END =================================================

Now in the Sun Java Application Server 9.1 I defined a Connection Pool with some of the information
like in the properties file above and was able to ping from there. So it seems o.k.

However, I don't think it uses that from the IDE. I might be wrong.

I'm basically trying to understand how the connection works from the IDE using Spring with Hibernate
in MyEclipse against Oracle db.

I'm not sure where else the jndi needs to be defined in order to work. Any help is appreciated.

Have a nice day.

Thanks,

T.


Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

What is the root cause of the exception. It would be the last cause at the bottom part of the stack trace. I am just thinking that it might be something else that is the real cause.

For a quick change, what happens if you put a "/" in your locations string in your PropertyPlaceholderConfigurer bean configuration. So

"classpath:/app.properties"

I am just thinking the root cause is that it isn't loading in your properties file. Just a guess here.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Ru Diaz
Greenhorn

Joined: Jan 08, 2009
Posts: 5
Hi Mark,

Thanks for the reply.

I tried the / in front of the app.properties like "classpath:/app.properties" as
you suggested and get the same trace error.

You might be right thinking that it is not loading the properties file. Is there
a way to verify that it is loading the file?

Below is the full stack trace with the errors that I get when trying to run the
dao test as a unit test:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sirsdataSource-direct' defined in URL [file:/C:/workspace/sirsweb/WebRoot/WEB-INF/classes/sirs-model-context.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'jndiName' is required
Caused by: java.lang.IllegalArgumentException: Property 'jndiName' is required
at org.springframework.jndi.JndiObjectLocator.afterPropertiesSet(JndiObjectLocator.java:90)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:146)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1198)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1167)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:427)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:285)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
at org.springframework.test.AbstractSingleSpringContextTests.createApplicationContext(AbstractSingleSpringContextTests.java:199)
at org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:179)
at org.springframework.test.AbstractSingleSpringContextTests.loadContext(AbstractSingleSpringContextTests.java:158)
at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:105)
at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:87)
at junit.framework.TestCase.runBare(TestCase.java:132)
at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:76)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

Thanks in advance for the reply. Any help is appreciated.

Have a great day.

Thanks,

Ru


Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

OK, I expected a bigger stack trace. But one of the reason why you might not have gotten one is because you have

<property name="ignoreResourceNotFound" value="true" />

in your PropertyPlaceholder. Remove that so we can see the real exception.

Actually, I see this too

<property name="jndiName" value="${connection.pool.datasource.standard}" />

for the property, but in your properties file you are not setting that to any value. It is empty. Don't you need a name?

You have this in your properies file for that entry

connection.pool.datasource.standard=

Mark
Ru Diaz
Greenhorn

Joined: Jan 08, 2009
Posts: 5
Hi Mark,

I removed the line that you requested and added for the datasource.standard (same as the one
for standard = appUserPool).

Then I ran the JUnit test and showed the same stack trace.

I was wondering, I have the pool defined in Sun Application Server 9.1. Does it need to be defined
anywhere else like in Oracle? If so how.

I'm don't know how it tries to resolve that. It seems that it uses the database server instead.

Thanks,

Ru


Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Well you are using the JndiObjectFactoryBean which looks things up for you in the JNDI tree. In your App Server, each can be different, you define a DataSource and it gets put into the JNDI tree.

For the property of the JndiObjectFactoryBean you need to provide the value for the jndiName property, and that needs to point to the jndi location of your datasource in your app server.

Mark
Ru Diaz
Greenhorn

Joined: Jan 08, 2009
Posts: 5
Hi Mark,

Thanks for the post. It took me a while to reply because I wanted to make sure that I setup the
connection pool right in the Sun Java Application Server. The connection pool is for Oracle and I
was able to ping and it says that it was successful.

Then I set a DataSource (also on the Sun Java Application Server 9.1) based on the connection pool.

That DataSource name is the same one referenced in the .properties files, properties for standard
and datasource pools.

Anyway, I noticed from looking around that people define a jndi.properties file and place it in the
test directory (when they have a setup that has one one part of the project for the code and a
separate one for testing (the junit tests) as I do. The test is linked (dependent) on the part that
has the source. I have a setup that has:

1 - mainapp
2 - testapp

but they're both part of the same project.

I placed the jndi.properties in the testapp\src directory. The jndi.properties file looks like this:

java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory
java.naming.provider.url=t3://localhost:7001

I'm looking and trying different things to change the inital and url values to whatever they should
be. I'm not using Weblogic, but Sun Java Application Server 9.1.

So far that's where I am now. Still stuck on this issue.

Have a nice day and thanks again.

Regards,

Ru


Ru Diaz
Greenhorn

Joined: Jan 08, 2009
Posts: 5
Now the new stack trace is:

org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: C:\Documents and Settings\rdiaz\.sirs\sirs.properties (The system cannot find the path specified)
Caused by: java.io.FileNotFoundException: C:\Documents and Settings\rdiaz\.sirs\sirs.properties (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
at org.springframework.core.io.UrlResource.getInputStream(UrlResource.java:103)
at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:179)
at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:158)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:68)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:467)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:334)
at org.springframework.test.AbstractSingleSpringContextTests.createApplicationContext(AbstractSingleSpringContextTests.java:199)
at org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:179)
at org.springframework.test.AbstractSingleSpringContextTests.loadContext(AbstractSingleSpringContextTests.java:158)
at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:105)
at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:87)
at junit.framework.TestCase.runBare(TestCase.java:132)
at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:76)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring jndi in context.xml / MyEclipse / Oracle / SJAS 9.1
 
Similar Threads
Dependency injection problem
Problem with Hibernate sessionFactoryBean in application context initialization
Spring+Hibernate can't create SessionFactory bean
spring transaction management only
Error creating bean with name 'sessionFactory' defined in ServletContext resource..please help