Hi
I created applicationContext.xml and hibernate.cfg.xml in MyProject/WebContent/WEB-INF
This configuration works, and my web application is able to retrieve database records from userDao.Code:<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="WEB-INF/hibernate.cfg.xml" /> ...... </bean> <bean id="userDao" class="com.myproject.dao.impl.UserDaoImpl"> <property name="sessionFactory" ref="sessionFactory" /> </bean>
Now, I created an unit test case for UserDao,
When run, it throws FileNotFoundException,Code:public class UserDaoTest { private ApplicationContext ctx; @Before public void setup() { ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); } ...... }
Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [WEB-INF/hibernate.cfg.xml] cannot be resolved to URL because it does not exist
It seems that I cannot specify WEB-INF/hibernate.cfg.xml, but changing this will cause my application not able to find the file during runtime.
Do you know how to resolve this problem?


Reply With Quote
