Java 将Spring引导部署到Weblogic时出现NoSuchMethodError

Java 将Spring引导部署到Weblogic时出现NoSuchMethodError,java,spring-boot,weblogic,Java,Spring Boot,Weblogic,我已经通过内置的tomcat服务器在本地运行了一个Spring Boot应用程序,但在Weblogic 12.2中将其作为war文件部署时遇到了问题。我按照《Spring引导参考指南》中的“85.1创建一个可部署的war文件”部分来构建war文件,创建了一个新的Weblogic托管服务器来托管它,并遵循了Weblogic上的部署安装步骤,但在部署中单击“服务所有请求”时出现以下异常。有什么建议吗 build.gradle的依赖项部分: dependencies { compile fil

我已经通过内置的tomcat服务器在本地运行了一个Spring Boot应用程序,但在Weblogic 12.2中将其作为war文件部署时遇到了问题。我按照《Spring引导参考指南》中的“85.1创建一个可部署的war文件”部分来构建war文件,创建了一个新的Weblogic托管服务器来托管它,并遵循了Weblogic上的部署安装步骤,但在部署中单击“服务所有请求”时出现以下异常。有什么建议吗

build.gradle的依赖项部分:

dependencies {
    compile fileTree(dir: 'lib', include: '*.jar')
    compile(
        'org.springframework.boot:spring-boot-starter-web:1.5.8.RELEASE',
        'org.springframework.boot:spring-boot-devtools',
        'org.springframework.boot:spring-boot-starter-jdbc',
        'org.springframework.boot:spring-boot-starter-data-jpa',
        'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.9.2',
        'org.springframework.boot:spring-boot-starter-security',
        'javax.servlet:javax.servlet-api:3.1.0'
    )
    testCompile(
        'org.springframework.security:spring-security-test',
        'org.springframework.boot:spring-boot-starter-test'
    )
    providedRuntime (
        'org.springframework.boot:spring-boot-starter-tomcat'
    )
}
@SpringBootApplication
public class Application extends SpringBootServletInitializer implements WebApplicationInitializer {

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

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
单击开始“为所有请求提供服务”时从Weblogic收到异常:

Caused By: java.lang.NoSuchMethodError: org.springframework.web.context.support.StandardServletEnvironment.initPropertySources(Ljavax/servlet/ServletContext;Ljavax/servlet/ServletConfig;)V
        at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:108)
        at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87)
        at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:162)
        at weblogic.servlet.internal.WebAppServletContext.initContainerInitializer(WebAppServletContext.java:1420)
        at weblogic.servlet.internal.WebAppServletContext.initContainerInitializers(WebAppServletContext.java:1359)
        Loads more weblogic errors here.
我的应用程序入口点似乎正常:

dependencies {
    compile fileTree(dir: 'lib', include: '*.jar')
    compile(
        'org.springframework.boot:spring-boot-starter-web:1.5.8.RELEASE',
        'org.springframework.boot:spring-boot-devtools',
        'org.springframework.boot:spring-boot-starter-jdbc',
        'org.springframework.boot:spring-boot-starter-data-jpa',
        'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.9.2',
        'org.springframework.boot:spring-boot-starter-security',
        'javax.servlet:javax.servlet-api:3.1.0'
    )
    testCompile(
        'org.springframework.security:spring-security-test',
        'org.springframework.boot:spring-boot-starter-test'
    )
    providedRuntime (
        'org.springframework.boot:spring-boot-starter-tomcat'
    )
}
@SpringBootApplication
public class Application extends SpringBootServletInitializer implements WebApplicationInitializer {

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

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

添加weblogic部署描述符,如中所述。创建一个名为
weblogic.xml
的文件,并将此代码添加到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/ejb-jar_3_0.xsd
        http://xmlns.oracle.com/weblogic/weblogic-web-app
        http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
    <wls:container-descriptor>
        <wls:prefer-application-packages>
            <wls:package-name>org.slf4j</wls:package-name>
            <wls:package-name>org.springframework.*</wls:package-name>
        </wls:prefer-application-packages>
    </wls:container-descriptor>
</wls:weblogic-web-app>
以及您的
build.gradle
添加依赖项

org.springframework.boot:spring-boot-starter-web
也删除

providedRuntime (
    'org.springframework.boot:spring-boot-starter-tomcat'
)

添加weblogic部署描述符,如中所述。创建一个名为
weblogic.xml
的文件,并将此代码添加到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/ejb-jar_3_0.xsd
        http://xmlns.oracle.com/weblogic/weblogic-web-app
        http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
    <wls:container-descriptor>
        <wls:prefer-application-packages>
            <wls:package-name>org.slf4j</wls:package-name>
            <wls:package-name>org.springframework.*</wls:package-name>
        </wls:prefer-application-packages>
    </wls:container-descriptor>
</wls:weblogic-web-app>
以及您的
build.gradle
添加依赖项

org.springframework.boot:spring-boot-starter-web
也删除

providedRuntime (
    'org.springframework.boot:spring-boot-starter-tomcat'
)

Spring引导嵌入了tomcat servlet容器。为什么要在weblogic上部署spring boot应用程序?有没有办法删除它?除非我误解了文档的意思,否则添加上面的“providedRuntime”依赖项会排除它吗?我们只是使用Weblogic作为我们的应用服务器。Spring boot嵌入了一个TomcatServlet容器。为什么要在weblogic上部署spring boot应用程序?有没有办法删除它?除非我误解了文档的意思,否则添加上面的“providedRuntime”依赖项会排除它吗?我们只是使用Weblogic作为我们的应用服务器。通过检查war文件内容完成并确认,但仍然存在相同的错误。我不确定weblogic是否在试图用自己的罐子代替春天的罐子?我不这么认为。请从
build.gradle
中删除您的
提供的运行时“org.springframework.boot:spring boot starter tomcat”
?然后问题可能出现在其他地方:(看起来Weblogic安装需要修补到最新版本。此后没有出现此问题。通过检查war文件内容完成并确认,但仍然存在相同的错误。我不确定是否是Weblogic试图将自己的JAR替换为spring JAR?我不这么认为。请删除您提供的
运行时的org.springframework.boot:spring boot starter tomcat'
来自
build.gradle
?然后问题可能出现在其他地方。:(看起来Weblogic安装需要修补到最新版本。此后没有出现此问题。