简体   繁体   English

在Weblogic中使用Java 7进行春季启动

[英]Spring boot with Java 7 in Weblogic

I have a requirement to deploy the spring boot application in weblogic server 11g. 我需要在weblogic服务器11g中部署spring boot应用程序。 The weblogic server supports only Java 7. Please assist me with the correct spring boot version and I get the following error if I use spring boot version 1.5.6.RELEASE. 该weblogic服务器仅支持Java7。请使用正确的Spring Boot版本帮助我,如果使用Spring Boot版本1.5.6.RELEASE,则会出现以下错误。

测试 On hover the following message gets displayed. 悬停时将显示以下消息。 "Multiple markers at this line - The type javax.servlet.ServletContext cannot be resolved. It is indirectly referenced from required .class files - The type javax.servlet.ServletException cannot be resolved. It is indirectly referenced from required .class files" “此行上有多个标记-无法解析类型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 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 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!";
    }
}

In src/main/webapp/WEB-INF folder, I have weblogic.xml and dispatcherServlet-servlet.xml 在src / main / webapp / WEB-INF文件夹中,我有weblogic.xml和dispatcherServlet-servlet.xml

I have excluded the embedded tomcat, because I need to deploy it in weblogic. 我排除了嵌入式tomcat,因为我需要将其部署在weblogic中。 Please help me with finding the issue. 请帮助我找到问题。

weblogic.xml 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 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">

Weblogic 11g(10.3.4) will support servlet 2.5(max). Weblogic 11g(10.3.4)将支持servlet 2.5(max)。 If needed to create an application using servlet 2.5, then web.xml is mandatory. 如果需要使用Servlet 2.5创建应用程序,则必须使用web.xml。 Spring boot's way of configuring the application by using SpringBootServletInitializer, WebApplicationInitializer will be supported from servlet 3.0 onwards only. Spring Boot通过使用SpringBootServletInitializer配置应用程序的方式,WebApplicationInitializer仅从Servlet 3.0开始受支持。 Thanks for the guidance M.Denium. 感谢您的指导M.Denium。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM