I know this question have been asked before, but I’ve been trying to get Spring working in Vaadin for three days now and I need answers.
Here’s what I’m doing
I’m using Vaadin, Maven, and Spring in Eclipse. I’m using Tomcat as my server; I’ve tried both mvn tomcat:run and Eclipse Run As Server → Tomcat. Different errors but no luck.
I’ve followed the Wiki solution pretty closely: I have web.xml sections like this:
I’ve changed the contextConfigLocation param-value to all sorts of things, including classpath*:spring-context, classpath*:/WEB-INF/spring-context.xml and others. One of the things the Wiki never tells you is
where to put the spring-context.xml file.
I have a SpringHelper class with a method like this:
It is
((WebApplicationContext) application.getContext()) that is returning null when I run as
mvn tomcat:run
When I start the project with Eclipse’s
Run on Server and run it on a Tomcat server started in Eclipse, I get this error:
SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
....
I also had problems at first trying to get Spring Hibernate/JPA and Vaadin integrated. I eventually got it working by using Aspect AOP and compile-time weaving. Here’s my configuration.
The file directory locations are as follows:
src/applicationContext.xml
src/META-INF/persistence.xml
src/META-INF/persistenceKH.xml
src/META-INF/spring/context.xml
WEB-INF/aop.xml
I also had to install the AOP jar files along with the usual jars.
applicationContext.xml - I am using multiple EntityManagerFactories and Transaction managers. I have since read of a better way of doing this but have not had time to go back and change it - but it works.
I have tried many different spring integration solutions for vaadin but all-in-all I ended up using the addon Spring-stuff.
It’s has actually solved more problems than I anticipated. It’s structure is very nice, two applicationContexts. One for application wide definitions and one for application instance definitions. I really recommend it.
I’m not as familiar with Aspect AOP as I should be. Two questions: 1) what is the AsepctJ file called and where does it go? and 2) could you give me some sample code for how you would get the Spring context into the class?
One more thing: I’m building a war file, but in development, do you use Eclipse? If so, do you use a Maven tomcat:run goal or start a Tomcat server in Eclipse to run the project?