我一直在开发阶段开发一个tomcat应用程序.随着我们前进,我的客户希望部署到websphere.我试图在websphere 8.5上这样做,但由于某种原因,我似乎遇到了问题.Tomcat很容易,我只是在战争中堕落,一切都像它应该的那样.Websphere是一个不同的故事.当我尝试点击我的应用程序时,我不断收到以下错误:
Error 404: SRVE0190E: File not found: {0}
Run Code Online (Sandbox Code Playgroud)
我一直在做一些研究,除了下面的一行,我没有注意到日志中有什么奇怪的.管理控制台说应用程序运行没有问题.
SRVE0292I: Servlet Message - [app#app.war]:.No Spring WebApplicationInitializer types detected on classpath
Run Code Online (Sandbox Code Playgroud)
我的应用程序是使用Java Config文件而不是传统的XML配置的,我猜不到这是问题的一部分?
我发现一篇博文说有些服务器设置需要应用.我试过那些没有成功的人:
com.ibm.ws.webcontainer.mapFiltersToAsterisk=true
com.ibm.ws.webcontainer.removetrailingservletpathslash=true
com.ibm.ws.webcontainer.invokeFiltersCompatibility=true
Run Code Online (Sandbox Code Playgroud)
我很茫然,有没有人有任何想法?
由于一些后续,我将发布我的web.xml和WebappInitializer:
@Order(2)
public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected String[] getServletMappings() {
return new String[]{"/"};
}
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] {ApplicationConfig.class, DataSourceConfig.class, JpaConfig.class, SecurityConfig.class, MailConfig.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[] {WebMvcConfig.class};
}
@Override
protected Filter[] getServletFilters() {
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setEncoding("UTF-8");
characterEncodingFilter.setForceEncoding(true);
return new Filter[] {characterEncodingFilter};
}
@Override
protected void customizeRegistration(ServletRegistration.Dynamic registration) {
registration.setInitParameter("defaultHtmlEscape", "true");
registration.setInitParameter("spring.profiles.active", "default");
}
}
Run Code Online (Sandbox Code Playgroud)
web.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0" metadata-complete="false">
<!-- Map all errors to Spring MVC handler method. See CustomErrorController.generalError() -->
<error-page>
<location>/generalError</location>
</error-page>
<session-config>
<session-timeout>15</session-timeout>
</session-config>
<display-name>eua</display-name>
</web-app>
Run Code Online (Sandbox Code Playgroud)
我对我的解决方案并不十分满意,但它暂时适用.Websphere对web.xml-less初始化的支持有点不合标准.甚至他们的技术人员的回复也没有帮助.最后,我不得不将一些spring初始化移动到web.xml.我仍然可以通过配置文件配置我的大部分JPA,安全性和Web功能,但我不得不给Spring一些kickstart.以下是我感兴趣的任何人改变的web.xml.感谢大家的帮助和指导.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<!-- Map all errors to Spring MVC handler method. See CustomErrorController.generalError() -->
<error-page>
<location>/generalError</location>
</error-page>
<session-config>
<session-timeout>15</session-timeout>
</session-config>
<display-name>app</display-name>
<context-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>org.proj.config.ApplicationConfig
org.proj.config.DefaultDataSourceConfig
org.proj.config.JpaConfig
org.proj.config.SecurityConfig
org.proj.config.MailConfig
org.proj.config.WebMvcConfig
</param-value>
</context-param>
<!-- Bootstrap the root application context as usual using ContextLoaderListener -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<!-- Again, config locations must consist of one or more comma- or space-delimited
and fully-qualified @Configuration classes -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>org.proj.config.ApplicationConfig
org.proj.config.DefaultDataSourceConfig
org.proj.config.JpaConfig
org.proj.config.SecurityConfig
org.proj.config.MailConfig
org.proj.config.WebMvcConfig
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>ERROR</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)
小智 5
在WebAppInitializer类上使用@Configuration批注
@Configuration
public class WebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) {
// Create the 'root' Spring application context
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(HibernateConfiguration.class);
// Manage the lifecycle of the root application context
container.addListener(new ContextLoaderListener(rootContext));
// Create the dispatcher servlet's Spring application context
AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext();
dispatcherServlet.register(SpringWebConfig.class);
// Register and map the dispatcher servlet
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherServlet));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13458 次 |
| 最近记录: |