Search code examples
spring-bootdeploymentmaven-3

Getting build errors for spring boot project


Trying to a create a basic webapp in spring boot and need to deploy it in weblogic 12.2.1 server

getting the below 2 errors in the java file

  • 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

Also I am not able to add the weblogic runtime to the application

could somebody help me regarding this ?

below is the 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.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.4.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-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-cache</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-web</artifactId>
              <exclusions>
                <exclusion>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
              </exclusions>
        </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>
    </dependencies>

    <build>
        <plugins>
      <plugin>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-war-plugin</artifactId>
         <configuration>
            <failOnMissingWebXml>false</failOnMissingWebXml>
            <archive>
               <manifest>
                  <addDefaultImplementationEntries>false</addDefaultImplementationEntries>
               </manifest>
            </archive>
         </configuration>
      </plugin>
   </plugins>
    </build>

</project>

And below is the java file DemoApplication.java

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.web.WebApplicationInitializer;

@SpringBootApplication
public class DemoApplication  extends SpringBootServletInitializer implements WebApplicationInitializer{

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

@Override
   protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
      return builder.sources(DemoApplication.class);
   }

}

while deploying the application to the weblogic server, getting the below exceptions

weblogic.application.ModuleException: java.lang.ClassNotFoundException: org.apache.tomcat.websocket.pojo.PojoEndpointBase
    at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
    at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
    at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:233)
    at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:228)
    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
    Truncated. see log file for complete stacktrace


Caused By: java.lang.ClassNotFoundException: org.apache.tomcat.websocket.pojo.PojoEndpointBase
    at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:1025)
    at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:986)
    at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:83)
    at weblogic.utils.classloaders.GenericClassLoader.doFindClass(GenericClassLoader.java:607)
    at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:539)
    Truncated. see log file for complete stacktrace

Solution

  • Just add this dependency to your pom

    <dependency> 
       <groupId>javax.servlet</groupId> 
       <artifactId>javax.servlet-api</artifactId>
       <version>3.1.0</version> 
       <scope>provided</scope> 
    </dependency>
    

    It is only needed at compile time, it will be provided runtime by the server container. So <scope>provided</scope> is added to pom dependency.

    Refer this link for more details.

    Hope this helps!