【问题标题】:Spring boot with Java 7 in Weblogic在 Weblogic 中使用 Java 7 进行 Spring Boot
【发布时间】:2019-08-13 03:18:27
【问题描述】:

我需要在 weblogic server 11g 中部署 spring boot 应用程序。 weblogic 服务器只支持 Java 7。请帮助我正确的 spring boot 版本,如果我使用 spring boot 版本 1.5.6.RELEASE,我会收到以下错误。

悬停时会显示以下消息。 “这条线上的多个标记 - 无法解析 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">

【问题讨论】:

  • 你的依赖是错误的。您排除了 tomcat,因此排除了 servlet api,这意味着您的代码会收到警告。在为部署创建战争时,不要排除依赖项,而是标记provided。同样不相关,但删除 @ComponentScan@EnableAutoConfiguration 已经被 @SpringBootApplication 暗示的那些。
  • 我在tomcat依赖中添加了provided并尝试了。当我尝试在 weblogic 11g 服务器中部署时,我不确定它是在 tomcat 还是 weblogic 上运行。我无法到达终点。
  • 相信我它在 weblogic 上运行。只有当 weblogic 启用了远程调试并且您被允许/能够连接到服务器时,您才能进行调试,否则您将无法调试。
  • 如果我点击端点,远程调试仍然启用,我得到 404 Not found 错误。如果我使用 spring 框架而不是 spring boot,则同样有效。
  • 检查您的日志并确保您调用的 URL 正确。

标签: spring spring-boot java-7 weblogic11g embedded-tomcat-7


【解决方案1】:

Weblogic 11g(10.3.4) 将支持 servlet 2.5(max)。如果需要使用 servlet 2.5 创建应用程序,则 web.xml 是必需的。 Spring Boot 使用 SpringBootServletInitializer 配置应用程序的方式,WebApplicationInitializer 将仅从 servlet 3.0 开始支持。 感谢 M.Denium 的指导。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-01
    • 1970-01-01
    • 2018-09-29
    • 2017-12-23
    • 2017-07-25
    • 1970-01-01
    相关资源
    最近更新 更多