I'm having problems accessing the sample springBoot application after I deploy it to Weblogic12C. It works fine using the springBoot-embedded Tomcat server.
Steps to reproduce: get the springBoot "getting started" application code following the steps: https://spring.io/guides/gs/spring-boot/
At this point, you can validate that all is well by running the gradle "bootRun" tasks which starts the app in the embedded Tomcat server. Once tomcat started, browse to localhost:8080/ and see that you get "Greetings from Spring Boot!"
java version "1.7.0_45" Java(TM) SE Runtime Environment (build 1.7.0_45-b18) Java HotSpot(TM) Server VM (build 24.45-b08, mixed mode)
At this point, you will see that the application deployed fine: - click on "deployments" again and see that your "complete" springBoot app is listed and ACTIVE - click on "complete" and notice on this page: "Context Root: /complete". NOTE: weblogic docs say that if there is no context-root defined in weblogic.xml, then it uses the name of the war file (minus the .war)
if you try to access the springBoot app at localhost:7001/complete you get a 403!!!
Error 403--Forbidden
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.4.4 403 Forbidden
The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated. If the request method was not HEAD and the server wishes to make public why the request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity. This status code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable.
Ok, so let's make one final change (I'm fishing here, maybe weblogic really wants a weblogic.xml):
edit weblogic.xml to contain:
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:weblogic-version>12.1.1</wls:weblogic-version>
<wls:context-root>testApp</wls:context-root>
</wls:weblogic-web-app>
now go back to your weblogic console (localhost:7001/console)
The 403 is still there. So:
In the sample code above, open the file gs-spring-boot\complete\src\main\java\hello\HelloController.java and replace:
@RequestMapping("/")
with this:
@RequestMapping("pierre.htm")
Now, if you browse to (remember weblogic.xml define context-root as /testApp):
And if you try on tomcat with "gradle bootrun", you can get to it fine: localhost:8080/pierre.htm (you get "greetings from SpringBoot!").
So this yields the following hints:
This is where I'm stuck... Can anyone think what JavaConfig "wiring" I'm missing to make it work on Weblogic? Any help greatly appreciated. Thanks!!
If anyone comes here, to make it simpler than read all the comments, below, here's how to make it work:
update the class WebInitializer so that it implements WebApplicationInitializer. So change it from this:
public class WebInitializer extends SpringBootServletInitializer {
To this:
public class WebInitializer extends SpringBootServletInitializer implements WebApplicationInitializer {
create a new file src/main/webapp/WEB-INF/weblogic.xml and put this contents in it:
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:weblogic-version>12.1.1</wls:weblogic-version>
<wls:context-root>helloApp</wls:context-root>
<wls:container-descriptor>
<wls:prefer-application-packages>
<wls:package-name>org.slf4j.*</wls:package-name>
</wls:prefer-application-packages>
</wls:container-descriptor>
</wls:weblogic-web-app>
start with the SpringBoot sample app and git the "complete" solution from here: spring.io/guides/gs/convert-jar-to-war/
take all the code from org.springframework.boot.context.web.SpringBootServletInitializer and copy it into HelloWebXml but change these lines:
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application; }
To this:
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
create a new file src/main/webapp/WEB-INF/weblogic.xml and put this contents in it:
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:weblogic-version>12.1.1</wls:weblogic-version>
<wls:context-root>helloApp</wls:context-root>
<wls:container-descriptor>
<wls:prefer-application-packages>
<wls:package-name>org.slf4j.*</wls:package-name>
</wls:prefer-application-packages>
</wls:container-descriptor>
</wls:weblogic-web-app>
NOTE: There is a similar questions here: Deploy Spring Boot app in Weblogic ...but that other question is about the deployment and it's a little vague (deployment itself works fine for me)
The problem with Weblogic is that it looks for a class that directly implements WebApplicationInitializer
to load the context. You probably extend SpringBootServletInitializer
. Try to
create a class that implemets WebApplicationInitializer
and copy the content of SpringBootServletInitializer
in it(you will need to also copy one package level class from the spring source, so your custom class can see it, as far as I remember).