How to make Spring play well with Wicket? (ContextLoaderListener problem)

As far as I know, and according to the instructions I found (like this and this too ), I need this in web.xml for Spring to work:

<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> 

In my Wicket application class, I will have:

 public class MyApplication extends WebApplication { @Override protected void init() { super.init(); addComponentInstantiationListener(new SpringComponentInjector(this)); } @Override public Class<? extends Page> getHomePage() { return HelloWorldPage.class; } } 

The problem is that whenever I have a ContextLoaderListener in web.xml, Wicket does not start. I just get 404 errors (or a blank page) and console output, for example:

 SEVERE: Error listenerStart Jun 28, 2011 12:49:04 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [1,973] milliseconds. Jun 28, 2011 12:49:04 PM org.apache.catalina.core.StandardContext startInternal SEVERE: Context [] startup failed due to previous errors Jun 28, 2011 12:49:04 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc SEVERE: The web application [] registered the JDBC driver [org.hsqldb.jdbc.JDBCDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. Jun 28, 2011 12:49:04 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc SEVERE: The web application [] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. Jun 28, 2011 12:49:04 PM org.apache.catalina.startup.HostConfig deployDirectory 

I use the latest versions of both frameworks (Wicket 1.4.17 and Spring 3.0.5) and Tomcat 7 to run them (the same thing happens with Tomcat 6). In addition, I have the following banks in WEB-INF / lib. Is something missing or too much?

 antlr-2.7.6.jar log4j-1.2.16.jar spring-web-3.0.5.jar commons-collections-3.1.jar mysql-connector-5.1.10.jar slf4j-api-1.6.1.jar dom4j-1.6.1.jar spring-beans-3.0.5.jar slf4j-log4j12-1.6.1.jar guava-r09.jar spring-context-3.0.5.jar wicket-1.4.17.jar hibernate-3.6.5.jar spring-core-3.0.5.jar wicket-auth-roles-1.4.17.jar hibernate-jpa-2.0-api-1.0.0.Final.jar spring-jdbc-3.0.5.jar wicket-datetime-1.4.17.jar hsqldb.jar spring-orm-3.0.5.jar wicket-ioc-1.4.17.jar javassist-3.12.0.GA.jar spring-test-3.0.5.jar wicket-spring-1.4.17.jar jta-1.1.jar spring-transaction-3.0.5.jar wicketstuff-annotation-1.4.17.2.jar 

The rest of web.xml (I tried setting up Wicket with servlet and filter, it doesn't matter):

 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <display-name>My App</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <context-param> <param-name>configuration</param-name> <param-value>development</param-value> </context-param> <filter> <filter-name>MyApp</filter-name> <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class> <init-param> <param-name>applicationClassName</param-name> <param-value>com.acme.MyApplication</param-value> </init-param> </filter> <filter-mapping> <filter-name>MyApp</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app> 

Google google found someone with the same problem but no solutions.

It's funny that I had Spring and Wicket that worked well together, with almost the same setup. Any ideas?

+4
source share
3 answers

Edit: Later I realized that the root problem here was most likely the missing log configuration . In our case (using SLF4J with log4j) after adding the correct configuration to log4j.properties all kinds of warnings and errors registered by libraries became visible even with Tomcat.


I tried Jetty instead of Tomcat and started getting improved error messages. Turns out there were a few missing libraries; necessary for some libraries that I have already used.

 2011-06-28 15:57:01.879:WARN::Unable to reach node goal: started java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:640) 

Some of the libraries seem to require a combo, which I added. Further:

 java.lang.NoClassDefFoundError: org/springframework/asm/ClassVisitor at org.springframework.context.support.AbstractRefreshableApplicationContext.customizeBeanFactory(AbstractRefreshableApplicationContext.java:218) 

Added spring -asm. Further:

 org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [applicationContext.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/config/AopNamespaceUtils 

Added spring -aop. Then something a little less straightforward:

 org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [applicationContext.xml]; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor 

Found a discussion about the lack of aopalgia in Spring blog comments . It seems to be completely removed from spring-aop, and you need to get aopalliance.jar from sourceforge .

(I think this swamp is Java EE in the worst case: I don't know what to do spring-asm or spring-aop not to mention aopalliance , but apparently I need them .: -P)

So, aopalliance.jar has been added. Later, I still needed to add spring-expression and cglib-2.2 (which comes with Hibernate).

After this, some problems with my Spring / Hibernate save level configuration remain, but they are not suitable for this question. Otherwise, Wicket and Spring now work beautifully (for example, to inject service-level objects on Wicket pages).

I think one moral of this is that in some cases, Tomcat eats useful error messages, and Jetty might be better for debugging. In addition, using Maven would probably help with the infernal hell a bit (but it’s not without problems).

0
source

This is the configuration of my project:

 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <!-- Spring context config location(s) --> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/applicationContext.xml </param-value> </context-param> <display-name>afrodite</display-name> <!-- used by Log4jConfigListener --> <context-param> <param-name>webAppRootKey</param-name> <param-value>afrodite.root</param-value> </context-param> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>/WEB-INF/log4j.properties</param-value> </context-param> <filter> <filter-name>openSessionInView</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </filter> <filter> <filter-name>afrodite-app</filter-name> <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class> <init-param> <param-name>applicationClassName</param-name> <param-value>info.afrodite.wicket.AfroditeApplication</param-value> </init-param> <init-param> <param-name>configuration</param-name> <param-value>DEPLOYMENT</param-value> </init-param> </filter> <!-- open session should be above the wicket filter --> <filter-mapping> <filter-name>openSessionInView</filter-name> <url-pattern>/app/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>afrodite-app</filter-name> <url-pattern>/app/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>afrodite-api</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>afrodite-api</servlet-name> <url-pattern>/api/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app> 

Hope this helps.

0
source

Please check contextConfigLocation . Parameter should be classpath *: applicationContext.xml . Please check the listener configuration also in my example. I hope I helped!

This is my web.xml configuration that works great:

 <?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <display-name>mywebapp</display-name> <filter> <filter-name>springRequestContextFilter</filter-name> <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class> </filter> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:applicationContext.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> <filter> <filter-name>wicket.mywebapp</filter-name> <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class> <init-param> <param-name>applicationClassName</param-name> <param-value>com.company.example.web.MyApplication</param-value> </init-param> </filter> <!-- Enables Spring Security --> <filter> <filter-name>filterChainProxy</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>filterChainProxy</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>wicket.mywebapp</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app> 
0
source

All Articles