|
I was able to resolve this two ways. The first was to change the testResources section to use src/main/webapp/WEB-INF instead of src/main/webapp.
<testResources> <testResource> <directory>src/test/resources</directory> <filtering>true</filtering> </testResource> <testResource> <directory>src/main/webapp/WEB-INF</directory> <filtering>true</filtering> <includes> <include>**/*.xml</include> </includes> </testResource> </testResources> After this, I changed it back to src/main/webapp and ran "mvn -U" to get the latest surefire-plugin. After getting the latest surefire version, the test passes when using the default (src/main/webapp). Hope this helps, Matt I had the same problem with the tutorial-hibernate.
After reading this ticket, I only had to run "mvn -U", and all my problems went away. Do you think you could add a note about this to the tutorial-hibernate? Thanks, Waldo I'll adjust the documentation if there's more reports of this problem on the mailing list.
Okay the first was a test I think my session timed out the first time I attempted to post. I'm writing an article on appfuse and as a result I'm passing through the tutorial. I noticed the same issues that have been mentioned above. With one exception the command 'mvn -U' did not work for me. The only thing that seemed to help was modifying the testResources area adding the WEB-INF to the directory. I emailed a colleague earlier today concerning this, and I've pasted a snippet from that email below. Please let me know if you need further information:
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 1.52 sec <<< FAILURE! testFindEntryByProjectNumber(com.oci.jnb.timeEntry.dao.TimeEntryDAOTest) Time elapsed: 1.482 sec <<< ERROR! org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.oci.jnb.timeEntry.dao.TimeEntryDAOTest': Unsatisfied dependency expressed through bean property 'timeEntryDao': Set this property value or disable dependency checking for this bean. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.checkDependencies(AbstractAutowireCapableBeanFactory.java:1213) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1038) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:291) at org.springframework.test.AbstractDependencyInjectionSpringContextTests.injectDependencies(AbstractDependencyInjectionSpringContextTests.java:230) at org.springframework.test.AbstractDependencyInjectionSpringContextTests.prepareTestInstance(AbstractDependencyInjectionSpringContextTests.java:195) So in my ApplicationContext I have the following definition, this file is located in the src/main/webapp/web-inf/ directory. <bean id="timeEntryDao" class="com.oci.jnb.timeEntry.dao.hibernate.TimeEntryDaoImpl"> <property name="sessionFactory" ref="sessionFactory"/> </bean> The TimeEntryDAOTest has the setter that I'm interested in injecting. So from the xml fragment above I'm trying to inject the "bean id=timeEntryDao" with the class TimeEntryDaoImpl. This setter is defined as: private TimeEntryDao dao = null; public void setTimeEntryDao(TimeEntryDao timeEntryDao) { dao = timeEntryDao; } The other interesting thing to note about the TimeEntryDAOTest is that it extends from BaseDaoTestCase which is an appFuse provided class and that extends from AbstractTransactionalDataSourceSpringContextTests. Inside the BaseDaoTestCase there is the following method that is returning config locations: protected String[] getConfigLocations() { setAutowireMode(AUTOWIRE_BY_NAME); return new String[] { "classpath:/applicationContext-resources.xml", "classpath:/applicationContext-dao.xml", "classpath*:/applicationContext.xml", // for modular projects "classpath:**/applicationContext*.xml" // for web projects }; } There are a couple things I don't understand about the method above, one is the asterisks surrounding the file names. It seems like the entry classpath*:/applicationContext.xml could be incorrect. Thanks for your time, Ryan You might try using a specific version of the maven-surefire-plugin:
<plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.3.1</version> </plugin> The available versions are listed at: http://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin |
||||||||||||||||||||||||||||||||||
While running a test, the context path for Spring are set to
AbstractSingleSpringContextTests.loadContextLocations(210) | Loading context for locations: classpath:/applicationContext-resources.xml,classpath:/applicationContext-dao.xml,classpath*:/applicationContext.xml,classpath:**/applicationContext*.xml
Maybe , the applicationContext.xml in the WEB-INF directory is not present in the path.
As of now, I am using applicationContext-resources for my spring DI