Annotation/java config based application starts to look for xml config file when moved from weblogic12c(12.1.3) to weblogic12cR2 (12.2.1)

寵の児 提交于 2019-12-06 05:35:37

问题


My spring java-config application packed as war runs wihout problem on weblogic 12.1.3 so I tried to deploy same war into weblogic 12.2.1 where it causes java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/DispatcherServlet-servlet.xml]. It seems like DispatcherServlet servlet is initialized with XmlWebApplicationContext (default one) instead of AnnotationConfigEmbeddedWebApplicationContext in 12.2.1 even when war is the same. Has someone any idea what was changed in weblogic implementation since previous version what is causing this problem?

Using same war:

  • in WLS 12.1.3 it is working without issue, application configures using annotations/java
  • in WLS 12.2.1 the same application looks for xml configuration at some point instead of configuring it using annotations/java as in 12.1.3.

回答1:


Had the same problem. I guess there is something wrong with WebLogic 12.2.1.

Try to manually set context class for Spring servlet, like so:

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));
    }

}

And everything will work fine again :)




回答2:


Sorry , I can't add a comment on the response of amariq.

Just a comment: if your WebApplicationInitializer extends AbstractDispatcherServletInitializer, you can override the method customizeRegistration like:

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



回答3:


I managed to get spring-boot 1.3.6.RELEASE working on Weblogic 12.2.1.

I had to create an empty (no declared beans) dispatcherServlet-servlet.xml file on src/main/webapp/WEB-INF directory.

Here is the file content:

    <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>

In addition, I made my main application class implement WebApplicationInitializer as stated on Spring Boot Ref Guide.

I am not sure if there are now two application contexts, but the one who is answering all my API calls seems to be working fine (dependency injection, aop, jdbc, jpa, logging, session context, actuator, etc).

PS: I have tried @amariq solution but it didn't work on Weblogic 12.2.1, only the one described above.




回答4:


I had the exact same issue here and tried the solutions suggested above, but they didn't work for me. I finally managed to make it work by doing a few modifications using this GitHub repo as reference.

They main points I could outline are:

  • pom.xml: add excludes for tomcat-embed-el dependency from spring-boot-starter-web
  • pom.xml: add dependency for spring-boot-legacy
  • add web.xml with contextConfigLocation, SpringBootContextLoaderListener and appServlet (in my previous configuration I had no web.xml at all)

Take a look at https://github.com/DISID/disid-proofs/tree/master/spring-boot-weblogic for further details.

I hope it helps.



来源:https://stackoverflow.com/questions/34408135/annotation-java-config-based-application-starts-to-look-for-xml-config-file-when

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!