【问题标题】:Deploy Spring boot and angular project to weblogic 12c将 Spring Boot 和 Angular 项目部署到 weblogic 12c
【发布时间】:2019-01-28 13:09:57
【问题描述】:

我正在尝试在 weblogic 12c (12.2.1) 上部署一个以 angular 作为前端的 spring-boot 应用程序。我的代码可在 - https://github.com/onkar0777/Angular-SpringBoot-REST-JWT

我用 mvn clean install 创建了一个战争,它在使用 java -jar 运行时运行良好

但是当我将相同的战争部署到 weblogic 时,在点击 http://192.168.1.6:7001/myweb 时出现错误(myweb 是上下文根)

Whitelabel 错误页面 此应用程序没有明确的映射 /error,因此您将其视为后备。

IST 2018 年 8 月 22 日星期三 13:28:58 出现意外错误 (类型=禁止,状态=403)。访问被拒绝

我猜想 weblogic 并没有将调用定向到 MainController

package com.app.api;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.*;

@ApiIgnore
@Controller // Dont use RestController as this method is mapping to a static file not a JSON
public class MainController {

  @RequestMapping(value={"/"})
    public String index() {
        return "index.html";
    }

}

MainApp.java

package com.app;

import javax.annotation.Resource;

import org.springframework.boot.Banner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.WebApplicationInitializer;

import com.app.services.StorageService;


@SpringBootApplication
@EnableJpaRepositories(basePackages ={ "com.app.repo"})
@EntityScan(basePackages ={ "com.app.model"})
@EnableTransactionManagement
public class MainApp extends SpringBootServletInitializer implements CommandLineRunner, WebApplicationInitializer {
    @Resource
    StorageService storageService;

    @Override
    public void run(String... arg) throws Exception {
        storageService.deleteAll();
        storageService.init();
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return configureApplication(builder);
    }

    public static void main(String[] args) {
        configureApplication(new SpringApplicationBuilder()).run(args);
    }

    private static SpringApplicationBuilder configureApplication(SpringApplicationBuilder builder) {
        return builder.sources(MainApp.class).bannerMode(Banner.Mode.OFF);
    }

}

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.4/weblogic-web-app.xsd">
    <wls:context-root>/myweb</wls:context-root>
    <wls:container-descriptor>
        <wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>
    </wls:container-descriptor>
</wls:weblogic-web-app>

【问题讨论】:

    标签: java angular spring-boot weblogic weblogic12c


    【解决方案1】:

    尝试将您的 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.4/weblogic-web-app.xsd">
    <wls:container-descriptor>
    
    <!-- <wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>-->
    <wls:prefer-application-packages>
    <wls:package-name>net.minidev.json.*</wls:package-name> 
    <wls:package-name>org.joda.*</wls:package-name>
    <wls:package-name>com.google.common.*</wls:package-name>
    <wls:package-name>javax.websocket.*</wls:package-name>
    <wls:package-name>javax.websocket.server.*</wls:package-name>
    <wls:package-name>org.slf4j.*</wls:package-name>
    </wls:prefer-application-packages>
    </wls:container-descriptor>
    </wls:weblogic-web-app>
    

    【讨论】:

      【解决方案2】:

      所以我解决了这个问题(延迟后在这里更新)。所以它原来是我的一些愚蠢的事情的组合。 对于在 weblogic 上使用 angular 前端部署应用程序而苦苦挣扎的人,代码与我在问题中发布的代码相同,所有更新都可以在 repo 上获得

      需要牢记的重要事项是:

      • 在 weblogic 中,您需要显式转到 index.html 文件以启动 UI,所以我需要转到这个确切的 url - http://192.168.1.6:7001/myweb/index.html
      • 基础 url 现在是 myweb,所以必须通过环境文件引入相应的更改
      • 要在 weblogic 上部署,您需要使用 base-href 选项构建 Angular 应用程序:

      ng build --prod --env=prod --base-href=/myweb/

      【讨论】: