部署 Spring 启动到 Weblogic 时出现 NoSuchMethodError
NoSuchMethodError when deploying Spring Boot to Weblogic
我有一个 Spring 引导应用程序 运行 通过内置的 tomcat 服务器在本地运行良好,但我在将其部署为 war 文件时遇到问题在 Weblogic 12.2 中。我按照 Spring 引导参考指南的“85.1 创建可部署的 war 文件”部分来构建 war 文件,创建了一个新的 Weblogic 托管服务器来托管它并遵循部署在 Weblogic 上安装步骤,但在部署上单击开始 "servicing all requests" 时出现以下异常。有什么建议么?
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 收到异常 "servicing all requests":
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);
}
}
如 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'
)
我有一个 Spring 引导应用程序 运行 通过内置的 tomcat 服务器在本地运行良好,但我在将其部署为 war 文件时遇到问题在 Weblogic 12.2 中。我按照 Spring 引导参考指南的“85.1 创建可部署的 war 文件”部分来构建 war 文件,创建了一个新的 Weblogic 托管服务器来托管它并遵循部署在 Weblogic 上安装步骤,但在部署上单击开始 "servicing all requests" 时出现以下异常。有什么建议么?
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 收到异常 "servicing all requests":
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);
}
}
如 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'
)