嗨,我正在将我的Spring应用程序从jboss 6迁移到wildfly 14。 我正在使用Spring版本3
在Jboss 6中,该应用程序没有发行任何发行版,当我尝试在Wildfly 14中对其进行部署时,出现了以下异常:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'applicationSessionListener' defined in "/C:/Produits/LDEV-BACK/wildfly-14.0.1.Final-EXA/bin/content/muses-web.war/WEB-INF/classes/fr/bdf/muses/manager/ApplicationSessionListener.class": Initialization of bean failed; nested exception is java.lang.IllegalStateException: UT010041: The servlet context has already been initialized, you can only call this method from a ServletContainerInitializer or a ServletContextListener:
是否可以在Wildfly 14上部署spring 3应用程序?如果可以,有人可以指导我解决此问题。
这是我的web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>myApp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<welcome-file-list>
<welcome-file>catalogue-archive.jsp</welcome-file>
</welcome-file-list>
<servlet-mapping>
<servlet-name>myApp</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<error-page>
<error-code>403</error-code>
<location>/erreur/403.jsp</location>
</error-page>
<error-page>
<error-code>405</error-code>
<location>/erreur/405.jsp</location>
</error-page>
<error-page>
<error-code>408</error-code>
<location>/erreur/408.jsp</location>
</error-page>
<error-page>
<location>/erreur/default.jsp</location>
</error-page>
<security-constraint>
<display-name>MYAPP USERS</display-name>
<web-resource-collection>
<web-resource-name>Public</web-resource-name>
<url-pattern>/css/*</url-pattern>
<url-pattern>/lib/*</url-pattern>
<url-pattern>/img/*</url-pattern>
<url-pattern>/wro/*</url-pattern>
<url-pattern>/erreur/*</url-pattern>
<url-pattern>/login-page.jsp</url-pattern>
<url-pattern>/logout.jsp</url-pattern>
<url-pattern>/auth.html</url-pattern>
<url-pattern>/auth/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<security-constraint>
<display-name>MYAPP USERS</display-name>
<web-resource-collection>
<web-resource-name>AUTHENTICATED_RESOURCE</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method-omission>OPTIONS</http-method-omission>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<security-constraint>
<display-name>MYAPP admin</display-name>
<web-resource-collection>
<web-resource-name>AUTHENTICATED_RESOURCE</web-resource-name>
<url-pattern>/admin-MYAPP/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>superviseur</role-name>
<role-name>FU1UA1416</role-name>
<role-name>FU_UA1416</role-name>
<role-name>FU1UA2113</role-name>
<role-name>FU_UA2113</role-name>
<role-name>FU1UA1482</role-name>
<role-name>FU_UA1482</role-name>
<role-name>FU1UA2504</role-name>
<role-name>FU_UA2504</role-name>
<role-name>FU1UA2109</role-name>
<role-name>FU_UA2109</role-name>
<role-name>AU_MYAPP_RSP</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<security-constraint>
<display-name>MYAPP debug</display-name>
<web-resource-collection>
<web-resource-name>AUTHENTICATED_RESOURCE</web-resource-name>
<url-pattern>/debug-MYAPP/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>superviseur</role-name>
<role-name>FU_UA2109</role-name>
<role-name>FU_UA2113</role-name>
<role-name>FU1UA2113</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<security-role>
<role-name>*</role-name>
</security-role>
<security-role>
<role-name>FU1UA2113</role-name>
</security-role>
<security-role>
<role-name>FU1UA1416</role-name>
</security-role>
<security-role>
<role-name>FU_UA2109</role-name>
</security-role>
<security-role>
<role-name>FU1UA2109</role-name>
</security-role>
<security-role>
<role-name>FU_UA2113</role-name>
</security-role>
<security-role>
<role-name>FU_UA1416</role-name>
</security-role>
<security-role>
<role-name>FU1UA1482</role-name>
</security-role>
<security-role>
<role-name>FU_UA1482</role-name>
</security-role>
<security-role>
<role-name>FU1UA2504</role-name>
</security-role>
<security-role>
<role-name>FU_UA2504</role-name>
</security-role>
<security-role>
<role-name>AU_MYAPP_RSP</role-name>
</security-role>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>ldapm</realm-name>
<form-login-config>
<form-login-page>/loginController.html</form-login-page>
<form-error-page>/erreur/auth.jsp</form-error-page>
</form-login-config>
</login-config>
<mime-mapping>
<extension>woff</extension>
<mime-type>application/font-woff</mime-type>
</mime-mapping>
<mime-mapping>
<extension>tff</extension>
<mime-type>application/font-tff</mime-type>
</mime-mapping>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>WebResourceOptimizer</filter-name>
<filter-class>ro.isdc.wro.http.WroFilter</filter-class>
</filter>
<!-- <filter> <filter-name>WebResourceOptimizer</filter-name> <filter-class>ro.isdc.wro.http.WroFilter</filter-class>
<init-param> <param-name>configuration</param-name> <param-value>${muses.wro4j.profile}</param-value>
</init-param> <init-param> <param-name>gzipResources</param-name> <param-value>FALSE</param-value>
</init-param> <init-param> <param-name>cacheUpdatePeriod</param-name> <param-value>60</param-value>
</init-param> <init-param> <param-name>modelUpdatePeriod</param-name> <param-value>600</param-value>
</init-param> <init-param> <param-name>jmxEnabled</param-name> <param-value>false</param-value>
</init-param> <init-param> <param-name>disableCache</param-name> <param-value>true</param-value>
</init-param> </filter> -->
<filter-mapping>
<filter-name>WebResourceOptimizer</filter-name>
<url-pattern>/wro/*</url-pattern>
</filter-mapping>
</web-app>
这是myApp-servlet.xm文件
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
<import resource="classpath*:/data-access-config.xml" />
<context:component-scan base-package="fr.sg.myApp"/>
<mvc:resources mapping="/**" location="/" />
<mvc:annotation-driven />
<bean id="sessionListener" class="fr.sg.myApp.manager.ApplicationSessionListener"></bean>
<mvc:interceptors>
<bean class="fr.sg.myApp.manager.CurrentUserInterceptor"></bean>
</mvc:interceptors>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/"/>
<property name="suffix" value=".jsp"/>
<property name="order" value="0"/>
</bean>
</beans>
这是我的Bean Spring
@Component
public class ApplicationSessionListener implements HttpSessionListener,
ApplicationContextAware {
private static int totalActiveSessions;
@Autowired
private ReportService reportService;
public static int getTotalActiveSession() {
return totalActiveSessions;
}
@Override
public void sessionCreated(HttpSessionEvent arg0) {
totalActiveSessions++;
HttpSession session = arg0.getSession();
Date now = new Date(session.getCreationTime());
reportService.createSession(session.getId(), now);
}
@Override
public void sessionDestroyed(HttpSessionEvent arg0) {
totalActiveSessions--;
HttpSession session = arg0.getSession();
Date now = new Date(session.getLastAccessedTime());
reportService.updateSession(session.getId(), now);
}
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
if (applicationContext instanceof WebApplicationContext) {
((WebApplicationContext) applicationContext).getServletContext()
.addListener(this);
} else {
// Either throw an exception or fail gracefully, up to you
throw new RuntimeException(
"Must be inside a web application context");
}
}
}