1

I am trying to deploy a spring-boot application with angular as the frontend on weblogic 12c (12.2.1). My code is available at - https://github.com/onkar0777/Angular-SpringBoot-REST-JWT

I have created a war with mvn clean install and it runs fine on running with java -jar

But when I deploy the same war to weblogic, on hitting http://192.168.1.6:7001/myweb I get the error (myweb is context-root)

Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed Aug 22 13:28:58 IST 2018 There was an unexpected error (type=Forbidden, status=403). Access Denied

I am guessing somehow weblogic is not directing calls to the 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>

3 Answers 3

1

So I solved this (updating here after a delay). So it turned out to be a combination of a few stupid things on my part. For anyone struggling with deploying apps with angular frontend on weblogic, code is same as I posted in the question and all updates are available on the repo

The important things which need to be kept in mind are:

  • In weblogic you need to explicitly go to the index.html file for the UI to get started, so I needed to go this exact url - http://192.168.1.6:7001/myweb/index.html
  • The base url is now myweb so had to introduce corresponding changes through environment files
  • For deployment on weblogic you need to build angular app with base-href option:

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

Sign up to request clarification or add additional context in comments.

Comments

0

Try modifying your weblogic.xml file to

<?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>

Comments

0

ng build --base-href /myweb --deploy-url /myweb/ for angular 15 I had to specify deploy-url also

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.