2014-02-11 61 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上重新部署應用程序後。

相關問題