无法将Spring App部署到Websphere [英] Cannot deploy Spring App to Websphere

查看:118
本文介绍了无法将Spring App部署到Websphere的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发阶段,我一直在开发tomcat的应用程序.随着我们的前进,我的客户希望部署到Websphere.我正在尝试在Websphere 8.5上执行此操作,但是由于某种原因,我似乎遇到了问题. Tomcat很容易,我只是参加战争,一切都按其应有的方式进行. Websphere是一个不同的故事.当我尝试打我的应用程序时,我不断收到以下错误:

I've been developing an application to tomcat during development phase. As we're moving forward, my client wants to be deployed to websphere. I'm attempting to do so on websphere 8.5, but for some reason I seem to be running into problems. Tomcat is easy, I'm just dropping in the war and everything works like it should. Websphere is a different story. I keep getting the following error when I try to hit my application:

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

我一直在做一些研究,除了下面一行以外,我没有注意到日志中有任何奇怪的地方.管理控制台说该应用程序正在正常运行.

I've been doing some research and aside from the one line below, I don't notice anything strange in the logs. The admin console says the application is running with no problems.

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

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

My application is configured using Java Config files instead of the traditional XML and I'm half guessing this is part of the problem?

我找到了一篇博客文章,说有些服务器设置需要应用.我尝试过那些没有成功的事情:

I found a blog post saying that there were some server settings that needed to be applied. I've tried those with no success:

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

我很茫然,有人有什么主意吗?

I'm at a loss, does anyone have any ideas?

由于需要跟进,我将发布我的web.xml和WebappInitializer:

Due to some followup, I'll post my web.xml and 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>

推荐答案

我对我的解决方案并不满意,但是暂时可行. Websphere对无web.xml初始化的支持有点不合标准.即使是他们技术人员的回复也无济于事.最后,我不得不将一些春季初始化工作移至web.xml.我仍然能够通过配置文件来配置我的大多数JPA,安全性和Web功能,但是我不得不给Spring一些帮助.以下是我为感兴趣的任何人更改的web.xml.感谢大家的帮助和指导.

I'm not terribly happy about my solution, but it works for the time being. Websphere's support of web.xml-less initialization is a bit sub-standard. Even replies from their techs were unhelpful. In the end I had to move a bit of the spring initialization to the web.xml. I was still able to configure most of my JPA, security, and Web features via config files, but I had to give Spring a bit of kickstart. Below is my altered web.xml for anyone that is interested. Thanks everyone for the help and guidance.

<?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>

这篇关于无法将Spring App部署到Websphere的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆