2014-02-11 64 views
9

我一直在开发阶段为tomcat开发应用程序。随着我们前进,我的客户希望部署到Websphere。我试图在websphere 8.5上这样做,但由于某种原因,我似乎遇到了问题。 Tomcat很简单,我只是投入战争,一切都像它应该的。 Websphere是另一回事。我不断收到以下错误,当我试着打我的应用程序:无法将Spring应用程序部署到Websphere

Error 404: SRVE0190E: File not found: {0} 

我一直在做一些研究,并一边从一个线下,我没有注意到任何在日志中奇怪。管理控制台表示应用程序正在运行,没有问题。

SRVE0292I: Servlet Message - [app#app.war]:.No Spring WebApplicationInitializer types detected on classpath 

我的应用程序配置使用Java配置文件,而不是传统的XML,我半猜猜这是问题的一部分?

我发现一篇博客文章说有一些服务器设置需要应用。我试过那些没有成功的:

com.ibm.ws.webcontainer.mapFiltersToAsterisk=true 
com.ibm.ws.webcontainer.removetrailingservletpathslash=true 
com.ibm.ws.webcontainer.invokeFiltersCompatibility=true 

我很茫然,有没有人有任何想法?

由于一些后续,我会后我的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"); 
    } 
} 

的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> 
+0

什么是FFDC日志?你的类加载器策略是如何配置的? –

+0

除非我尝试击中{context}/x,否则FFDC日志中没有任何内容。当我打到根时,什么都没有去。对于类加载器策略,我尝试了许多组合。我在某处读到parent_last应该工作,但那也没有帮助。 –

+0

您是否安装了WebSphere的所有修订包?在ServletContextInitializer的东西里有一些修正。理论上它应该工作。你如何创建你的战争/ jar文件? Web-INF/classes中的WebAppInitializer或者WEB-INF/lib中的jar中? –

回答

4

我不是非常高兴我的解决方案,但它目前工作。 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> 
+1

我有同样的问题,我会尝试你的方法,并让你知道。提前致谢。 –

+0

您可能想尝试确保安装了所有最新的websphere fixpacks。有人在几周前评论说最近的补丁修复了这个问题。如果没有,我的解决方案最终会为我的项目工作。 –

+0

我正在使用IBM BPM,并且每周都有修复程序,您的解决方案正在运行,因此我投票支持您。 Thx –

3

我有类似的问题。 Websphere对可以扫描的类的数量有一些默认限制。而这个SpringBoot主类可能不在这个范围内。就我而言,当我设置此JVM属性-Dclassinfocachesize = 10000(应用程序服务器> server1的>进程定义> Java虚拟机>通用JVM参数>),并重新启用在

2

对我来说,工作液为IBM的问题就解决了WAS ND 8.5.0是直接实现接口WebApplicationInitializer:

To deploy a Spring Boot application to Weblogic you must ensure that your servlet initializer directly implements WebApplicationInitializer (even if you extend from a base class that already implements it).

SpringBoot 74.4

1

这个问题是通过APAR PM85177的WebSphere ND固定。该修补程序已集成到WAS8.0.0.8和后续版本中。在WebAppInitializer类

+0

这一条线索/答案将我的痛苦变成了巨大的喜悦。我希望我能用更多的投票来宣传这个答案。谢谢张zhang。 –

3

使用@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("/"); 

    } 

} 
1

两个加@Configuration注释和直接实现WebApplicationInitializer可以解决这个问题。 (经过测试的Websphere 8.5.0.2)

0

我也面临同样的问题。我的Spring MVC(Spring 4。3)Rest应用程序正在Jboss上工作,但是当我尝试在Websphere 8.5.5上部署时,我得到了同样的错误:SRVE0292I:Servlet消息 - [app#app.war]:没有在类路径上检测到Spring WebApplicationInitializer类型。我尝试了这篇文章和其他文章中提出的所有选项,但没有解决。最后我发现了这个问题。当我创建Spring MVC Rest应用程序时,我使用maven archetype创建项目,并使用空白web.xml创建Spring MVC应用程序。正如我计划使用Spring4,基于java的初始化,我留下了arechetype创建的web.xml,并没有在web.xml中配置我的dispatcherServlet。 Jboss足够聪明,可以忽略空白的web.xml并查找java初始化类并将应用程序启动。在WebSphere 8.5.5上部署相同的应用程序时,WebSphere找到空白web.xml并在web.xml中查找DispatcherServlet信息,而不是查找Java初始化程序类。删除web.xml并在WebSphere上重新部署应用程序后。

相关问题