2015-12-22 36 views
4

時,基於註釋/ java配置的應用程序開始尋找xml配置文件我的spring java-config應用程序打包爲war,但運行weblogic 12.1.3時沒有問題我試圖將相同的戰爭部署到weblogic 12.2.1,它導致了java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/DispatcherServlet-servlet.xml]。 即使在戰爭是相同的情況下,DispatcherServlet servlet在12.2.1中似乎也被初始化爲XmlWebApplicationContext(默認值)而不是AnnotationConfigEmbeddedWebApplicationContext。 有沒有人知道什麼是以前版本的weblogic實現中發生了什麼變化是什麼導致了這個問題?當從weblogic12c(12.1.3)移動到weblogic12cR2(12.2.1)

使用相同war

  • 在WLS 12.1.3它的工作沒有問題,應用程序配置使用註釋/ JAVA
  • 在WLS 12.2.1同一應用程序在某些時候會查找XML配置,而不是在12.1.3中使用annotations/java進行配置。

回答

2

有同樣的問題。我猜WebLogic 12.2.1出了問題。

嘗試手動設置上下文類爲Spring的servlet,就像這樣:

public class ApplicationInitializer implements WebApplicationInitializer { 

    @Override 
    public void onStartup(ServletContext container) throws ServletException { 
     AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); 
     // <some context configuration> 

     ServletRegistration.Dynamic spring = container.addServlet("Spring", new DispatcherServlet(context)); 
     // <some servlet configuration> 

     // Here, set desired context class using 'contextClass' parameter. 
     spring.setInitParameter("contextClass", context.getClass().getName()); 

     container.addListener(new ContextLoaderListener(context)); 
    } 

} 

而且一切都將重新工作的優良:)

+0

我不能得到這個工作。獲取以下錯誤「無法初始化上下文,因爲已經存在根應用程序上下文 - 請檢查您的web.xml中是否有多個ContextLoader *定義!」。這個方法與Spring已經提供的方法有什麼不同? – Kristoffer

+0

@Kristoffer,好吧,不知道,但我想你實際上有多個上下文定義? Spring提供了三種方法來執行我在我的答案中描述的基於註釋的配置,但其中只有兩種適用於WebLogic 12c:我正在使用或使用Spring Boot。所以... :) – amariq

1

對不起,我不能在響應添加評論amariq。

只是評論:如果你的WebApplicationInitializer延伸AbstractDispatcherServletInitializer,你可以重寫像方法customizeRegistration:

@Override 
protected void customizeRegistration(ServletRegistration.Dynamic registration) { 
    registration.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName()); 
} 
0

我這裏有相同的問題,並試圖解決方案上面的建議,但他們並沒有爲工作我。我終於設法通過使用this GitHub repo作爲參考進行一些修改來使其工作。

我可以勾勒出他們要點是:

  • pom.xml:爲tomcat-embed-el依賴從spring-boot-starter-web
  • pom.xml添加excludes:添加依賴於spring-boot-legacy
  • 添加web.xmlcontextConfigLocationSpringBootContextLoaderListenerappServlet(在我以前的配置我根本沒有web.xml

查看https://github.com/DISID/disid-proofs/tree/master/spring-boot-weblogic瞭解更多詳情。

我希望它有幫助。

1

我設法讓Spring-Boot 1.3.6.RELEASE在Weblogic 12.2.1上工作。

我不得不創建一個空的(沒有聲明豆)的DispatcherServlet-servlet.xml中文件上的src /主/ web應用/ WEB-INF目錄

以下是文件內容:

<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context.xsd"> 

    </beans> 

另外,我做我的主應用程序類實現WebApplicationInitializer上Spring Boot Ref Guide的說明。

我不確定現在是否有兩個應用程序上下文,但回答我所有API調用的人似乎工作正常(依賴注入,aop,jdbc,jpa,日誌記錄,會話上下文,執行器等) 。 PS:我已經嘗試過@amariq解決方案,但它並沒有在Weblogic 12.2.1上工作,只有上面描述的那個。