Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot deploy Spring App to 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

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?

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>
like image 602
Harley Jackson Avatar asked Feb 11 '14 22:02

Harley Jackson


People also ask

Can we deploy spring boot application in WebSphere?

To deploy spring boot to WebSphere 9 you would want to choose War packaging and Java 8. The zip file from the spring initializr includes a Help.md file with links to helpful documentation. After you extract the zip file, use File -> Import existing maven project into a new workspace.

Can we deploy Microservices in WebSphere Application Server?

WebSphere Application Server features and benefitsCreate and deploy cloud-native and web-based apps and microservices quickly with a lightweight and composable production runtime that features a single administrative console for Java and Node.

Can we deploy jar file in WebSphere?

If you are running WebSphere® Application Server , as an alternate approach, you can also add the . jar file directly from the WebSphere Application Server administrative console using the following path: Application servers > servername > Process Definition > Java Virtual Machine > Classpath.

Can spring boot run without Tomcat?

You can use Spring Boot without embedded Tomcat web server if you don't need it. Just exclude embedded Tomcat from Spring Boot Web Starter (spring-boot-starter-web).


2 Answers

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.

like image 167
STK Avatar answered Sep 20 '22 08:09

STK


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>
like image 39
Harley Jackson Avatar answered Sep 20 '22 08:09

Harley Jackson