在Weblogic12C上访问SpringBoot示例应用程序的全新部署时遇到问题 [英] Problems accessing fresh deploy of SpringBoot sample app on Weblogic12C

查看:900
本文介绍了在Weblogic12C上访问SpringBoot示例应用程序的全新部署时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将示例springBoot应用程序部署到Weblogic12C后,无法访问它.使用嵌入了springBoot的Tomcat服务器,它可以很好地工作.

使用SpringBoot嵌入式Tomcat安装和测试:一切都很好

重现步骤:按照以下步骤获取springBoot入门"应用程序代码: https ://spring.io/guides/gs/spring-boot/

  • git clone https://github.com/spring-guides/gs -spring-boot.git
  • cd gs-spring-boot/complete/(我们将使用gr-spring-boot/complete目录,这样您不必浏览上面的入门"页面(所有更改已为您完成)在完整"中).
  • 打开文件gs-spring-boot/complete/build.gradle并在其他应用插件"条目下方添加"Apply plugin:'war'"

这时,您可以通过运行gradle"bootRun"任务(在嵌入式Tomcat服务器中启动该应用程序)来验证一切正常. tomcat启动后,浏览至localhost:8080/,然后看到"Spring Boot的问候!"

现在让我们将其安装在Weblogic 12C上

  • 运行"gradle war"(同样,从gs-spring-boot/complete/开始工作) 您现在将在gs-spring-boot \ complete \ build \ libs \ complete.war下有一个war文件
    • 转到您的weblogic12C控制台.我没有对WL12C进行更改,因此控制台位于localhost:7001/console.注意:一周前,我从Oracle网站下载了WL12C开发人员版本.下载后,我没有对其进行任何更改. WL12C下载的开发版本要求我们将其指向已经安装的JDK.我的WL12C使用Java版本:

      java版本"1.7.0_45" Java(TM)SE运行时环境(内部版本1.7.0_45-b18) Java HotSpot(TM)服务器VM(内部版本24.45-b08,混合模式)

    • 在控制台中时,部署war文件:
    • 单击部署"
    • 点击安装"
    • 浏览给您"gs-spring-boot \ complete \ build \ libs"目录
    • 选择"complete.war"旁边的单选按钮,然后单击下一步"
    • 选择安装为应用程序",然后单击下一步
    • 将所有选项保留为[仅DD,使用默认设置,使用相同的可访问性],然后单击下一步
    • 单击完成

这时,您将看到应用程序部署良好: -再次单击部署",然后看到您的完整" springBoot应用已列出且处于活动状态 -单击完成",然后在此页面上注意:上下文根:/complete".注意:weblogic文档说,如果在weblogic.xml中没有定义上下文根,则它将使用war文件的名称(减去.war)

现在,问题是:收到403:

如果您尝试访问位于localhost:7001/complete的springBoot应用程序,则会收到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.

好吧,让我们做一个最后的更改(我在这里钓鱼,也许weblogic确实想要一个weblogic.xml):

  • 创建目录:gs-spring-boot \ complete \ src \ main \ webapp \ WEB-INF \
  • 创建此文件:gs-spring-boot \ complete \ src \ main \ webapp \ WEB-INF \ weblogic.xml
  • 编辑weblogic.xml以包含:

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

  • 现在返回您的weblogic控制台(localhost:7001/控制台)

  • 转到"Web应用程序",然后选中完成"旁边的复选框,然后单击删除"
  • 重新启动您的weblogic12C服务器(只是偏执)
  • 再次运行渐变清洁"然后渐变战争"任务,以生成新的战争文件
  • (使用winzip或其他方式)打开war文件并确认war文件现在具有WEB-INF/weblogic.xml
  • 转到控制台以部署新的war文件(使用与上述相同的步骤)
  • 确认该应用程序现已部署,并且具有/testApp的contextRoot(在weblogic.xml中定义)
  • 浏览到localhost:7001/testApp/

403仍然存在.所以:

    webli确实了解此应用程序(返回403).因为如果它不了解该应用程序,它将返回404(通过转到localhost:7001/doesNotExist尝试它,您将得到404)
  • ,但看起来WL12C不会将请求路由到spring.过去,我们会在web.xml中定义一堆东西,但如今,使用javaConfig和SpringBoot,这一切都应该自动完成.
    • 注意:因为SpringBoot使用JavaConfig(Servlet3),所以我们不能使用任何低于weblogic12C(最新的版本)

我尝试的另一件事:更改RequestMapping

在上面的示例代码中,打开文件gs-spring-boot \ complete \ src \ main \ java \ hello \ HelloController.java并替换:

@RequestMapping("/")

与此:

@RequestMapping("pierre.htm")

现在,如果您浏览(记住weblogic.xml将context-root定义为/testApp):

  • localhost:7001/testApp/pierre.htm,您将获得404
  • localhost:7001/testApp/,您将获得403

如果您使用"gradle bootrun"尝试安装tomcat,则可以正常使用:localhost:8080/pierre.htm(您将获得来自SpringBoot的问候!").

所以这会产生以下提示:

  • Weblogic确实了解/testApp
  • Weblogic不知道/testApp/pierre.htm是什么.就像从未将其配置为RequestMapping一样.
  • 缺少一些弹簧接线",使其无法在Weblogic上工作....

这就是我所困的地方...谁能想到我缺少的JavaConfig以便在Weblogic上正常工作?任何帮助,不胜感激.谢谢!

解决方案

如果有人来这里,要使其比阅读下面的所有评论更简单,以下是使其工作的方法:

  • 从SpringBoot示例应用程序开始,然后从此处git完整"解决方案:spring.io/guides/gs/convert-jar-to-war/
  • 更新类WebInitializer,以实现WebApplicationInitializer.因此,从此进行更改:

        public class WebInitializer extends SpringBootServletInitializer {
    

对此:

        public class WebInitializer extends SpringBootServletInitializer implements WebApplicationInitializer {

  • 创建一个新文件src/main/webapp/WEB-INF/weblogic.xml并将其内容放入其中:

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

    • 等级战争
    • 部署到Weblogic12C
    • 它现在应该可以工作了:)非常感谢Dave Syer和Evgeni!

以前的解决方案(此处为后代保留)

  • 从SpringBoot示例应用程序开始,并从此处git完整"解决方案:spring.io/guides/gs/convert-jar-to-war/

    • 在示例应用程序的程序包"hello"中,添加一个新的公共类HelloWebXml,它实现了WebApplicationInitializer
    • 从org.springframework.boot.context.web.SpringBootServletInitializer中获取所有代码,并将其复制到HelloWebXml中,但更改以下几行:

      受保护的SpringApplicationBuilder configure(SpringApplicationBuilder应用程序){ 退货申请; }

对此:

    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
      return application.sources(Application.class);
    }

  • 将类org.springframework.boot.context.web.ErrorPageFilter复制到示例应用程序中的包"hello"中
  • 创建一个新文件src/main/webapp/WEB-INF/weblogic.xml并将其内容放入其中:

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

    • 等级战争
    • 部署到Weblogic12C
    • 它现在应该可以工作了:)非常感谢Dave Syer和Evgeni!

注意:这里有一个类似的问题: 在Weblogic中部署Spring Boot应用 ...但是另一个问题是关于部署的问题,这有点模糊(部署本身对我来说很好)

解决方案

Weblogic的问题在于,它寻找直接直接实现WebApplicationInitializer的类来加载上下文.您可能扩展了SpringBootServletInitializer.尝试 创建一个实现WebApplicationInitializer的类,并在其中复制SpringBootServletInitializer的内容(据我所知,您还需要从spring源代码中复制一个包级别的类,以便您的自定义类可以看到它)./p>

I'm having problems accessing the sample springBoot application after I deploy it to Weblogic12C. It works fine using the springBoot-embedded Tomcat server.

Install and test using SpringBoot-embedded Tomcat: all is well

Steps to reproduce: get the springBoot "getting started" application code following the steps: https://spring.io/guides/gs/spring-boot/

  • git clone https://github.com/spring-guides/gs-spring-boot.git
  • cd gs-spring-boot/complete/ (we'll be using the gr-spring-boot/complete dir so that you don't have to go through the "getting started" page above (all changes done for you in "complete").
  • open the file gs-spring-boot/complete/build.gradle and add " apply plugin: 'war' " below the other "apply plugin" entries

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

Now let's install this on Weblogic 12C

  • run "gradle war" (again, work from gs-spring-boot/complete/) you will now have a war file under gs-spring-boot\complete\build\libs\complete.war
    • go to your weblogic12C console. I didn't make changes to my WL12C so the console is located at localhost:7001/console NOTE: I downloaded the WL12C developer version one week ago from the Oracle site. I didn't make any changes to it, as downloaded. The dev version of WL12C download requires that we point it to our already installed JDK. My WL12C uses java version:

      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)

    • when in the console, deploy the war file:
    • click on "deployments"
    • click on "install"
    • browse to you "gs-spring-boot \ complete \ build \ libs" dir
    • select the radio button next to complete.war and hit next
    • select "install as application" and hit next
    • leave all options as is [DD only, use the defaults, use same accessibility] and hit next
    • click finish

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)

Now, the problem: getting a 403:

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

  • create the dir: gs-spring-boot\complete\src\main\webapp\WEB-INF\
  • create this file: gs-spring-boot\complete\src\main\webapp\WEB-INF\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)

  • go to "web applications" and select the checkbox next to "complete" then hit "delete"
  • restart your weblogic12C server (just to be paranoid)
  • run the "gradle clean" then "gradle war" task again to generate a new war file
  • open the war file (using winzip or whatever) and confirm that the war file now has WEB-INF/weblogic.xml
  • go to the console the deploy the new war file (use same steps as above)
  • confirm that the app is now deployed and has a contextRoot of /testApp (as defined in weblogic.xml)
  • browse to localhost:7001/testApp/

The 403 is still there. So:

  • weblogic DOES know about this application (returns 403). Because if it didn't know about the application, it would return 404 (try it by going to localhost:7001/doesNotExist and you'll get 404)
  • but it looks like WL12C doesn't route requests to spring. In the past, we'd define a bunch of things in web.xml but nowadays, with javaConfig and SpringBoot, this should all be done automagically...
    • note: because SpringBoot uses JavaConfig (Servlet3), we can't use anything lower that weblogic12C (which is the latest)

Another thing I tried: change RequestMapping

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

  • localhost:7001/testApp/pierre.htm you'll get a 404
  • localhost:7001/testApp/ you'll get 403

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:

  • Weblogic does know about /testApp
  • Weblogic has no idea what /testApp/pierre.htm is. It's like it was never configured as a RequestMapping.
  • there is some "Spring wiring" missing for it to work on weblogic....

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

Solution

If anyone comes here, to make it simpler than read all the comments, below, here's how to make it work:

  • start with the SpringBoot sample app and git the "complete" solution from here: spring.io/guides/gs/convert-jar-to-war/
  • 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>
    

    • gradle war
    • deploy to Weblogic12C
    • it should work now :) Thanks so much to both Dave Syer and Evgeni!

Previous Solution (kept here for posterity)

  • start with the SpringBoot sample app and git the "complete" solution from here: spring.io/guides/gs/convert-jar-to-war/

    • in the sample app's package "hello", add a new public class HelloWebXml implements WebApplicationInitializer
    • 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);
    }

  • copy the class org.springframework.boot.context.web.ErrorPageFilter into package "hello" in the sample app
  • 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>
    

    • gradle war
    • deploy to Weblogic12C
    • it should work now :) Thanks so much to both Dave Syer and Evgeni!

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

这篇关于在Weblogic12C上访问SpringBoot示例应用程序的全新部署时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆