Cannot deploy Spring App to Websphere

后端 未结 7 1586
傲寒
傲寒 2020-12-31 09:28

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

相关标签:
7条回答
  • 2020-12-31 09:59

    this issue is fixed by APAR PM85177 for WebSphere ND. The fix is integrated in WAS8.0.0.8 and following version.

    0 讨论(0)
  • 2020-12-31 10:00

    For me working solution for IBM WAS ND 8.5.0 was to implement directly interface 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

    0 讨论(0)
  • 2020-12-31 10:04

    use @Configuration annotation on the WebAppInitializer class

    @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("/");
    
        }
    
     }
    
    0 讨论(0)
  • 2020-12-31 10:06

    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>
    
    0 讨论(0)
  • 2020-12-31 10:17

    Both adding @Configuration annotation and directly implementing WebApplicationInitializer can resolve this issue. (Tested for Websphere 8.5.0.2)

    0 讨论(0)
  • 2020-12-31 10:17

    I faced the same issue too. My Spring MVC (Spring 4.3) Rest application was working on Jboss, but when I tried deploying on Websphere 8.5.5 I got the same error: SRVE0292I: Servlet Message - [app#app.war]:.No Spring WebApplicationInitializer types detected on classpath. I tried all the options suggested in this post and other posts, but nothing worked out. Finally I found the issue. When I created the Spring MVC Rest application I used maven archetype to create the project and it created the Spring MVC application with blank web.xml. As I planned to use Spring4, java based initialization, I left arechetype created web.xml like that and didn't configure my dispatcherServlet in web.xml. Jboss was intelligent enough to ignore blank web.xml and finding java initializer class and bringing the application up. Where as the same application deployed on WebSphere 8.5.5, WebSphere found the blank web.xml and looking for the DispatcherServlet info in the web.xml and not looking for the java initializer class. After removing the web.xml and redeploying the application is up on WebSphere.

    0 讨论(0)
提交回复
热议问题