[英]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服务器可以正常工作。
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/
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的问候!”
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,混合模式)
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)
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):
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)
The 403 is still there. 403还在那里。 So:
所以:
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):
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: 所以这会产生以下提示:
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!!
谢谢!!
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. 更新类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>
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/
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);
}
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>
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.