3

I have a requirement to deploy the spring boot application in weblogic server 11g. 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.

test 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"

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!";
    }
}

In src/main/webapp/WEB-INF folder, I have weblogic.xml and dispatcherServlet-servlet.xml

I have excluded the embedded tomcat, because I need to deploy it in weblogic. Please help me with finding the issue.

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

Sowmea shree
  • 89
  • 2
  • 11
  • Your dependencies are wrong. You excluded tomcat and hence the servlet api, which means your code gets warnings. When creating a war for deployment don't exclude dependencies but rather mark the `provided`. Also unrelated but remove the `@ComponentScan` and `@EnableAutoConfiguration` those are already implied by `@SpringBootApplication`. – M. Deinum Mar 25 '19 at 07:01
  • I added `provided` in tomcat dependency and tried. When I try to deploy in weblogic 11g server, I am not sure if it is running on tomcat or weblogic. I am unable to hit the endpoint. – Sowmea shree Mar 26 '19 at 06:16
  • Trust me it is running on weblogic. You will only be able to debug if the weblogic has remote debugging enabled and you are allowed/able to connect to the server, else you won't be able to debug. – M. Deinum Mar 26 '19 at 06:36
  • The remote debugging is enabled still if I hit the endpoint I get 404 Not found error. The same works if I use spring framework instead of spring boot. – Sowmea shree Mar 26 '19 at 09:56
  • Check your logs and make sure you are calling the correct URL. – M. Deinum Mar 26 '19 at 10:02
  • I noticed that once I add the application in server I get this warning - ` ` – Sowmea shree Mar 27 '19 at 02:51
  • Can someone guide with the xml file that needs to be added in WEB-INF folder. I added weblogic.xml and dispatcherServlet-servlet.xml. Should it be web.xml? – Sowmea shree Mar 27 '19 at 03:33
  • Why would you need a web.xml? Which servlet container version is Weblogic 11g? I fyou need a `web.xml` you also need a different way of bootstrapping your applicaion. – M. Deinum Mar 27 '19 at 07:36
  • The version am using is 2.5. Weblogic server 11g(10.3.6) supports servlet v2.5(max). I added the weblogic and dispatcherservlet xml files. I have no idea why the endpoint is not getting invoked. – Sowmea shree Mar 27 '19 at 08:42
  • Which explains why it doesn't work. You are using the Servlet 3.0 way of bootstrapping, so your application won't run. You will need a `web.xml` together with [Spring Boot Legacy](https://github.com/dsyer/spring-boot-legacy) to bootstrap the application. – M. Deinum Mar 27 '19 at 08:48
  • Oh, I will try out this way. Thank you. – Sowmea shree Mar 27 '19 at 08:55
  • M. Deinum, I would like to request you to upvote my question if you think it is appropriate. Thank you. – Sowmea shree Mar 31 '19 at 08:03
  • Did you find a final configuration that working ? i'd like to get such please if you have – Adir Dayan Aug 16 '21 at 08:15

1 Answers1

0

Weblogic 11g(10.3.4) will support servlet 2.5(max). If needed to create an application using servlet 2.5, then web.xml is mandatory. Spring boot's way of configuring the application by using SpringBootServletInitializer, WebApplicationInitializer will be supported from servlet 3.0 onwards only. Thanks for the guidance M.Denium.

Sowmea shree
  • 89
  • 2
  • 11