据我所知,根据我找到的说明(如 this 和 this too ),我需要在 web.xml 中使用此文件才能使 Spring 工作:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
在我的 Wicket 应用程序类中,我有:
public class MyApplication extends WebApplication {
@Override
protected void init() {
super.init();
addComponentInstantiationListener(new SpringComponentInjector(this));
}
@Override
public Class<? extends Page> getHomePage() {
return HelloWorldPage.class;
}
}
问题是,只要我在 web.xml 中有 ContextLoaderListener,Wicket 就不会启动。我只会收到 404 错误(或空白页),控制台输出如下:
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
我正在使用这两个框架的最新版本(Wicket 1.4.17 和 Spring 3.0.5)和 Tomcat 7 来运行它们(同样的事情发生在 Tomcat 6 上)。另外,我在 WEB-INF/lib 中有以下 jars。东西少了还是太多了?
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
web.xml 的其余部分(我已经尝试使用 servlet 和过滤器设置 Wicket;没有区别):
<?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>
谷歌搜索我找到了someone with the same problem , 但没有解决方案。
有趣的是,我以前曾让 Spring 和 Wicket 很好地协同工作,而且设置几乎相同。有什么想法吗?
最佳答案
这是我项目的配置:
<?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>
希望这会有所帮助。
关于java - 如何让 Spring 与 Wicket 兼容? (ContextLoaderListener 问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6504940/