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=jdbc:oracle: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.