我需要在weblogic服务器11g中部署spring boot应用程序。该weblogic服务器仅支持Java7。如果使用的是Spring Boot版本1.5.6.RELEASE,请为我提供正确的Spring Boot版本,并且出现以下错误。
悬停时将显示以下消息。 “这条线上有多个标记 -无法解析类型javax.servlet.ServletContext。间接引用自 所需的.class文件 -无法解析类型javax.servlet.ServletException。间接引用自 所需的.class文件”
Application.java
package com.example.ap;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.WebApplicationInitializer;
@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan({ "com.example.ap" })
public class Application extends SpringBootServletInitializer implements
WebApplicationInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder
builder) {
return builder.sources(Application.class);
}
}
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.ap</groupId>
<artifactId>test</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath />
</parent>
<properties>
<java-version>1.7</java-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
ResourceController.java
package com.example.ap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/resource")
public class ResourceController {
@RequestMapping(method = RequestMethod.GET)
String readResource() {
return "hello!";
}
}
在src / main / webapp / WEB-INF文件夹中,我有weblogic.xml和dispatcherServlet-servlet.xml
我排除了嵌入式tomcat,因为我需要将其部署在weblogic中。请帮助我找到问题。
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.3/weblogic-web-app.xsd">
<wls:context-root>sg-manutouch-lite-api</wls:context-root>
<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-version>10.3.6</wls:weblogic-version>
</wls:weblogic-web-app>
dispatcherServlet-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">
答案 0 :(得分:0)
Weblogic 11g(10.3.4)将支持servlet 2.5(max)。如果需要使用Servlet 2.5创建应用程序,则必须使用web.xml。 Spring Boot通过使用SpringBootServletInitializer配置应用程序的方式,WebApplicationInitializer仅从Servlet 3.0开始受支持。 感谢M.Denium的指导。