【问题标题】:403 Forbidden - Deploying Spring Boot application in Weblogic403 Forbidden - 在 Weblogic 中部署 Spring Boot 应用程序
【发布时间】:2017-03-30 20:03:10
【问题描述】:

我有一个应用程序,我目前正尝试将其转换为 Spring Boot,但在配置 Weblogic 以运行该应用程序时遇到问题。我在 HTTP 请求上收到 403 Forbidden 响应。


任何帮助将不胜感激!


这是我的@SpringBootApplication 课程。

@SpringBootApplication
public class AgisSpringApplication extends SpringBootServletInitializer implements WebApplicationInitializer {

    public static void main(String[] args) {
        SpringApplication.run(AgisSpringApplication.class, args);
    }

    @Override
    public void onStartup(ServletContext context) throws ServletException {

    }
}

这是我的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/ejb-jar_3_0.xsd
        http://xmlns.oracle.com/weblogic/weblogic-web-app
        http://xmlns.oracle.com/weblogic/weblogic-web-app/1.7/weblogic-web-app.xsd">
    <wls:weblogic-version>12.1.3</wls:weblogic-version>
    <wls:context-root>agis-spring</wls:context-root>
    <wls:container-descriptor>
        <wls:prefer-application-packages>
            <wls:package-name>org.slf4j.*</wls:package-name>
        </wls:prefer-application-packages>
    </wls:container-descriptor>
</wls:weblogic-web-app>

这是我目前唯一的控制器

@RestController
public class MapController {

    private TemplateService templateService;

    public MapController(TemplateService templateService) {
        this.templateService = templateService;
    }

    @GetMapping("/")
    public String getName() throws Exception {
        return templateService.getTemplate("map.vm");
    }
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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.group</groupId>
    <artifactId>agis-spring</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>agis-spring</name>
    <description></description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-velocity</artifactId>
            <version>1.4.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

【问题讨论】:

  • 你把你的神器打包成war了吗?您是否从中排除了嵌入式 tomcat?

标签: java spring spring-boot weblogic weblogic12c


【解决方案1】:

1) 您的 Application.java 看起来不正确。 试试这个:

@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) throws Exception {
        SpringApplication.run(Application.class, args);
    }
}

2) 确保您的weblogic.xml 位于src/main/webapp/WEB-INF/ 下。

3) 确保将应用打包到war

<packaging>war</packaging>

4) 确保嵌入式 tomcat 已禁用。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

5) 我不确定wls:package-name 是否可以指定为通配符。根据spring-boot documentation 应该是这样的:

<wls:package-name>org.slf4j</wls:package-name>

6) 通过执行mvn clean package 构建war 工件。

.war 工件将被放置到 your-app/build/lib。使用此文件部署到服务器中。

希望这些提示能解决问题。

【讨论】:

  • 现在要尝试所有这些东西。谢谢!我会尽快回复。
  • 当我们使用之前版本的 spring 时,weblogic.xml 位于src/main 之外的不同目录中。这真的很重要吗?
  • 不完全是,这取决于您如何构建应用程序。主要思想是打包后应该像这样定位your-app.war/WEB-INF/weblogic.xml。尝试使用任何存档管理器打开您的war 文件,并确保文件夹结构正常。
  • 我想我可能误解了这个过程......我实际上找不到战争文件。它不在项目的根目录中。
  • 我已经添加了我的pom.xml
猜你喜欢
  • 2014-09-10
  • 1970-01-01
  • 2015-12-28
  • 1970-01-01
  • 1970-01-01
  • 2017-04-07
  • 2018-09-13
  • 1970-01-01
  • 2022-12-19
相关资源
最近更新 更多