Java 在 Weblogic 中部署 Spring Boot 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24835051/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 15:05:07  来源:igfitidea点击:

Deploy Spring Boot app in Weblogic

javaspringspring-bootweblogic12c

提问by Carlos

I'm having a trouble deploying a Spring boot application in webLogic 12C.

我在 webLogic 12C 中部署 Spring 启动应用程序时遇到问题。

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.

10.4.4 403 Forbidden 服务器理解请求,但拒绝满足它。授权无济于事,不应重复该请求。如果请求方法不是 HEAD 并且服务器希望公开请求未完成的原因,它应该在实体中描述拒绝的原因。当服务器不想透露请求被拒绝的确切原因时,或者当没有其他响应适用时,通常使用此状态代码。

I was wondering if someone can help with that.

我想知道是否有人可以提供帮助。

采纳答案by Pierre

I reviewed your code and saw an issue in this class of your code: https://github.com/purrox/Spring-example/blob/master/src/main/java/hello/Application.java

我查看了您的代码并在您的此类代码中看到了一个问题:https: //github.com/purrox/Spring-example/blob/master/src/main/java/hello/Application.java

You're doing it correctly (as defined in the SpringBoot docs) but it seems there's a bug with Weblogic12C (or maybe an interpretation of the standard). It seems like Weblogic12C Searches for a class that implements WebApplicationInitializer DIRECTLY. Notice how your code extends SpringBootServletInitializer (which implements WebApplicationInitializer). Weblogic12C doesn't like it that way it seems. So, the simplest way is to make your Application class implement WebApplicationInitializer. So, change this line:

您做得正确(如 SpringBoot 文档中所定义),但似乎 Weblogic12C 存在错误(或者可能是对标准的解释)。似乎 Weblogic12C 搜索直接实现 WebApplicationInitializer 的类。请注意您的代码如何扩展 SpringBootServletInitializer(实现 WebApplicationInitializer)。Weblogic12C 不喜欢它看起来的样子。因此,最简单的方法是让您的 Application 类实现 WebApplicationInitializer。所以,改变这一行:

public class Application extends SpringBootServletInitializer {  

to this:

对此:

public class Application extends SpringBootServletInitializer implements WebApplicationInitializer {  

Note: once you fix the above, you'll run into another Weblogic12C deploy issue: "java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath". To fix that other issue, create a new file src/main/webapp/WEB-INF/weblogic.xml and put this content in it:

注意:一旦您修复了上述问题,您将遇到另一个 Weblogic12C 部署问题:“java.lang.IllegalArgumentException:LoggerFactory 不是 Logback LoggerContext 但 Logback 在类路径上”。要解决其他问题,请创建一个新文件 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>

回答by dan carter

You need to add "implements WebApplicationInitializer" to your hello.Application.

您需要在 hello.Application 中添加“implements WebApplicationInitializer”。

This is redundant as it extends SpringBootServletInitializer, which itself implements WebApplicationInitializer, however, as @Pierre points out, weblogic requires a class to directly implement it.

这是多余的,因为它扩展了 SpringBootServletInitializer,它本身实现了 WebApplicationInitializer,但是,正如@Pierre 指出的那样,weblogic 需要一个类来直接实现它。

回答by Naresh Hawk

If you are going to use multipartfile request, you may still find issues in deploying the war.

如果您打算使用multipart文件请求,您可能仍然会在部署War时发现问题。

The root of the problem is that OrderedCharacterEncodingFilter is running after HiddenHttpMethodFilter. HiddenHttpMethodFiltertriggers processing of the request body as it calls getParameteron the request. OrderedCharacterEncodingFilterthen runs and sets the request's encoding. Setting the request's encoding after its body has been processed is bad and, on WebLogic, causes the request to lose track of all its multipart data.

问题的根源在于 OrderedCharacterEncodingFilter 在 HiddenHttpMethodFilter 之后运行。HiddenHttpMethodFilter在调用请求时触发请求正文的处理getParameterOrderedCharacterEncodingFilter然后运行并设置请求的编码。在处理完请求正文后设置请求的编码是错误的,并且在 WebLogic 上会导致请求丢失对其所有多部分数据的跟踪。

A workaround is to disable the character encoding filter in application.properties:

解决方法是禁用 application.properties 中的字符编码过滤器:

spring.http.encoding.enabled: false

回答by kpater87

I hit this issue last time. After applying all proposals from this post I was still getting error 403. In my case the problem was in the web.xmlfile. I was using version 2.5 instead of 3.0 without configuring it to load an ApplicationContextvia a DispatcherServlet.

我上次碰到这个问题。在应用了这篇文章中的所有建议后,我仍然收到错误 403。就我而言,问题出在web.xml文件中。我使用的是 2.5 版而不是 3.0 版,但没有将其配置为ApplicationContext通过DispatcherServlet.

From the post: What exactly is the web-app version? What does it affect?.

来自帖子:网络应用程序版本到底是什么?它有什么影响?.

Versioning refers to XML schema version that syntax of your web.xml file must obey. More important, it also indicates the version of Servlet specification that your application implements.

And from Spring documentation http://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html:

从 Spring 文档http://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html

Older Servlet containers don't have support for the ServletContextInitializer bootstrap process used in Servlet 3.0. You can still use Spring and Spring Boot in these containers but you are going to need to add a web.xml to your application and configure it to load an ApplicationContext via a DispatcherServlet.

Finally I've changed the version of web.xmlfile to 3.0 and it starts working.

最后我将web.xml文件的版本更改为 3.0,它开始工作。