将Spring Boot部署到Weblogic时的NoSuchMethodError

时间:2017-12-19 09:33:15

标签: java spring-boot weblogic

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

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'
    )
}

点击开始时收到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.

我的应用程序入口点似乎没问题:

@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);
    }
}

1 个答案:

答案 0 :(得分:3)

添加spring-docs中所述的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>

现在将weblogic.xml文件放入WEB-INF文件夹,以便完整路径为WEB-INF/weblogic.xml

<强>更新 将空dispatcher-servlet.xml添加到WEB-INF/文件夹。

<强>调度-servlet.xml中

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>

您的build.gradle添加依赖

org.springframework.boot:spring-boot-starter-web

同时删除

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