简体   繁体   English

在Weblogic12C上访问SpringBoot示例应用程序的新部署时出现问题

[英]Problems accessing fresh deploy of SpringBoot sample app on Weblogic12C

I'm having problems accessing the sample springBoot application after I deploy it to Weblogic12C. 我将它部署到Weblogic12C后访问示例springBoot应用程序时遇到问题。 It works fine using the springBoot-embedded Tomcat server. 使用springBoot嵌入式Tomcat服务器可以正常工作。

Install and test using SpringBoot-embedded Tomcat: all is well 使用SpringBoot嵌入式Tomcat进行安装和测试:一切都很好

Steps to reproduce: get the springBoot "getting started" application code following the steps: https://spring.io/guides/gs/spring-boot/ 重现步骤:按照以下步骤获取springBoot“入门”应用程序代码: https ://spring.io/guides/gs/spring-boot/

  • git clone https://github.com/spring-guides/gs-spring-boot.git 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"). cd gs-spring-boot / complete /(我们将使用gr-spring-boot / complete目录,这样你就不必浏览上面的“入门”页面了(所有更改都在“完成”中完成) “)。
  • open the file gs-spring-boot/complete/build.gradle and add " apply plugin: 'war' " below the other "apply plugin" entries 打开文件gs-spring-boot / complete / build.gradle并在其他“apply plugin”条目下添加“apply plugin:'war'”

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. 此时,您可以通过运行gradle“bootRun”任务来验证一切正常,这些任务在嵌入式Tomcat服务器中启动应用程序。 Once tomcat started, browse to localhost:8080/ and see that you get "Greetings from Spring Boot!" 一旦tomcat启动,浏览到localhost:8080 /并看到你得到“来自Spring Boot的问候!”

Now let's install this on Weblogic 12C 现在让我们在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 运行“gradle war”(再次,从gs-spring-boot / complete /工作)你现在将在gs-spring-boot \\ complete \\ build \\ libs \\ complete.war下有一个war文件
    • go to your weblogic12C console. 转到您的weblogic12C控制台。 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. 我没有对WL12C进行更改,因此控制台位于localhost:7001 / console注意:我在一周前从Oracle站点下载了WL12C开发人员版本。 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. WL12C下载的开发版要求我们将它指向已安装的JDK。 My WL12C uses java version: 我的WL12C使用java版本:

      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) java版“1.7.0_45”Java(TM)SE运行时环境(版本1.7.0_45-b18)Java HotSpot(TM)服务器VM(版本24.45-b08,混合模式)

    • when in the console, deploy the war file: 在控制台中,部署war文件:
    • click on "deployments" 点击“部署”
    • click on "install" 点击“安装”
    • browse to you "gs-spring-boot \\ complete \\ build \\ libs" dir 浏览你“gs-spring-boot \\ complete \\ build \\ libs”目录
    • select the radio button next to complete.war and hit next 选择complete.war旁边的单选按钮,然后点击下一步
    • select "install as application" and hit next 选择“安装为应用程序”并点击下一步
    • leave all options as is [DD only, use the defaults, use same accessibility] and hit next 保留所有选项[仅限DD,使用默认值,使用相同的辅助功能]并点击下一步
    • 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". 此时,您将看到应用程序部署正常: - 再次单击“部署”,看到您的“完整”springBoot应用程序已列出并且活动 - 单击“完成”并在此页面上注意:“上下文根:/完成”。 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) 注意:weblogic文档说如果weblogic.xml中没有定义上下文根,那么它使用war文件的名称(减去.war)

Now, the problem: getting a 403: 现在,问题是:获得403:

if you try to access the springBoot app at localhost:7001/complete you get a 403!!! 如果您尝试访问localhost:7001 /完成的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.

Ok, so let's make one final change (I'm fishing here, maybe weblogic really wants a weblogic.xml): 好吧,让我们做一个最后的改变(我在这里钓鱼,也许weblogic真的想要一个weblogic.xml):

  • create the dir: gs-spring-boot\\complete\\src\\main\\webapp\\WEB-INF\\ 创建目录:gs-spring-boot \\ complete \\ src \\ main \\ webapp \\ WEB-INF \\
  • create this file: gs-spring-boot\\complete\\src\\main\\webapp\\WEB-INF\\weblogic.xml 创建此文件:gs-spring-boot \\ complete \\ src \\ main \\ webapp \\ WEB-INF \\ weblogic.xml
  • edit weblogic.xml to contain: 编辑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> 
  • now go back to your weblogic console (localhost:7001/console) 现在回到你的weblogic控制台(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) 重新启动你的weblogic12C服务器(只是为了偏执)
  • run the "gradle clean" then "gradle war" task again to generate a new war file 再次运行“gradle clean”然后“gradle war”任务以生成新的war文件
  • open the war file (using winzip or whatever) and confirm that the war file now has WEB-INF/weblogic.xml 打开war文件(使用winzip或其他)并确认war文件现在有WEB-INF / weblogic.xml
  • go to the console the deploy the new war file (use same steps as above) 转到控制台部署新的war文件(使用与上面相同的步骤)
  • confirm that the app is now deployed and has a contextRoot of /testApp (as defined in weblogic.xml) 确认该应用程序现已部署,并且具有/ testApp的contextRoot(如weblogic.xml中所定义)
  • browse to localhost:7001/testApp/ 浏览到localhost:7001 / testApp /

The 403 is still there. 403还在那里。 So: 所以:

  • weblogic DOES know about this application (returns 403). weblogic了解此应用程序(返回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) 因为如果它不知道应用程序,它将返回404(尝试通过转到localhost:7001 / doesNotExist,你会得到404)
  • but it looks like WL12C doesn't route requests to spring. 但看起来WL12C并没有将请求路由到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... 在过去,我们在web.xml中定义了一堆东西但是现在,使用javaConfig和SpringBoot,这应该都是自动完成的......
    • note: because SpringBoot uses JavaConfig (Servlet3), we can't use anything lower that weblogic12C (which is the latest) 注意:因为SpringBoot使用JavaConfig(Servlet3),所以我们不能使用任何低于weblogic12C的东西(这是最新的)

Another thing I tried: change RequestMapping 我尝试的另一件事:更改RequestMapping

In the sample code above, open the file gs-spring-boot\\complete\\src\\main\\java\\hello\\HelloController.java and replace: 在上面的示例代码中,打开文件gs-spring-boot \\ complete \\ src \\ main \\ java \\ hello \\ HelloController.java并替换:

@RequestMapping("/")

with this: 有了这个:

@RequestMapping("pierre.htm")

Now, if you browse to (remember weblogic.xml define context-root as /testApp): 现在,如果您浏览(记住weblogic.xml将context-root定义为/ testApp):

  • localhost:7001/testApp/pierre.htm you'll get a 404 localhost:7001 / testApp / pierre.htm你会得到404
  • localhost:7001/testApp/ you'll get 403 localhost:7001 / testApp /你将获得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!"). 如果你尝试使用“gradle bootrun”运行tomcat,你可以很好地使用它:localhost:8080 / pierre.htm(你得到“来自SpringBoot的问候!”)。

So this yields the following hints: 所以这会产生以下提示:

  • Weblogic does know about /testApp Weblogic确实了解/ testApp
  • Weblogic has no idea what /testApp/pierre.htm is. Weblogic不知道/testApp/pierre.htm是什么。 It's like it was never configured as a RequestMapping. 它就像从未配置为RequestMapping。
  • there is some "Spring wiring" missing for it to work on weblogic.... 有一些“春天布线”缺少它在weblogic上工作....

This is where I'm stuck... Can anyone think what JavaConfig "wiring" I'm missing to make it work on Weblogic? 这就是我被困住的地方......任何人都可以想到JavaConfig“缺少布线”是什么让它在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/ 从SpringBoot示例应用程序开始,然后从这里获取“完整”解决方案:spring.io/guides/gs/convert-jar-to-war/
  • update the class WebInitializer so that it implements WebApplicationInitializer. 更新类WebInitializer,以便它实现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: 创建一个新文件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> 
    • gradle war gradle war
    • deploy to Weblogic12C 部署到Weblogic12C
    • it should work now :) Thanks so much to both Dave Syer and Evgeni! 它现在应该工作:)非常感谢Dave Syer和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/ 从SpringBoot示例应用程序开始,然后从这里获取“完整”解决方案:spring.io/guides/gs/convert-jar-to-war/

    • in the sample app's package "hello", add a new public class HelloWebXml implements WebApplicationInitializer 在示例应用程序的包“hello”中,添加一个新的公共类HelloWebXml实现WebApplicationInitializer
    • take all the code from org.springframework.boot.context.web.SpringBootServletInitializer and copy it into HelloWebXml but change these lines: 从org.springframework.boot.context.web.SpringBootServletInitializer中获取所有代码并将其复制到HelloWebXml中,但更改以下行:

      protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application; protected SpringApplicationBuilder configure(SpringApplicationBuilder应用程序){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 将类org.springframework.boot.context.web.ErrorPageFilter复制到示例应用程序中的“hello”包中
  • create a new file src/main/webapp/WEB-INF/weblogic.xml and put this contents in it: 创建一个新文件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> 
    • gradle war gradle war
    • deploy to Weblogic12C 部署到Weblogic12C
    • it should work now :) Thanks so much to both Dave Syer and Evgeni! 它现在应该工作:)非常感谢Dave Syer和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) 注意:这里有一个类似的问题: 在Weblogic中部署Spring Boot应用程序 ......但是另一个问题是关于部署而且它有点模糊(部署本身对我来说很好)

The problem with Weblogic is that it looks for a class that directly implements WebApplicationInitializer to load the context. Weblogic的问题在于它查找直接实现WebApplicationInitializer以加载上下文的类。 You probably extend SpringBootServletInitializer . 您可能会扩展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). 尝试创建一个实现WebApplicationInitializer的类并在其中复制SpringBootServletInitializer的内容(您还需要从spring源复制一个包级别类,因此您的自定义类可以看到它,据我所记)。

The soluation by Evgeni works thanks. Evgeni的解决方案非常有效。 But i have an improvement. 但我有所改善。

Rather than take a copy of the SpringBootServletInitializer and ErrorPageFilter, you can continue to extend it, but simply add a redundant "implements WebApplicationInitializer" to your class: 您可以继续扩展它,而不是获取SpringBootServletInitializer和ErrorPageFilter的副本,而只需向您的类添加冗余的“implements WebApplicationInitializer”:

@Configuration
@EnableJpaRepositories
@EnableAutoConfiguration
@ComponentScan("nz.co.myapp")
public class Application extends SpringBootServletInitializer implements WebApplicationInitializer {

    /** Used for running in war */
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

}

用于Application类型的冗余超接口WebApplicationInitializer,已由SpringBootServletInitializer定义

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM