编程语言
首页 > 编程语言> > spring – 从weblogic12c(12.1.3)移动到weblogic12cR2(12.2.1)时,基于注释/ java配置的应用程序开始查找xml配置文件

spring – 从weblogic12c(12.1.3)移动到weblogic12cR2(12.2.1)时,基于注释/ java配置的应用程序开始查找xml配置文件

作者:互联网

我的spring java-config应用程序打包为战争在weblogic 12.1.3上运行没问题所以我试图将同样的war部署到weblogic 12.2.1中,导致java.io.FileNotFoundException:无法打开ServletContext资源[/ WEB-INF / DispatcherServlet -servlet.xml后缀.
似乎DispatcherServlet servlet在12.2.1中使用XmlWebApplicationContext(默认值)而不是AnnotationConfigEmbeddedWebApplicationContext进行初始化,即使war相同也是如此.
有人知道自上一版本以来weblogic实现中发生了哪些变化导致了这个问题?

使用相同的战争:

>在WLS 12.1.3中它没有问题,应用程序使用注释/ java进行配置
>在WLS 12.2.1中,相同的应用程序在某个时刻查找xml配置,而不是像12.1.3中那样使用注释/ java来配置它.

解决方法:

有同样的问题.我猜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));
    }

}

一切都会好起来的:)

标签:spring,spring-java-config,weblogic12c
来源: https://codeday.me/bug/20190623/1270976.html