Skip to content

Spring Boot app as a module #22013

@winster

Description

@winster

Hi,

I have a legacy java application which is a monolith web based on servlet. We want to develop new APIs but outside the monolith. But dependencies with the monolith is a problem. Hence we are exploring to use Java9 modules in the legacy app. As a first step, we just make the whole monolith under a module by folder refactoring and add a module-info.java which exports certain packages. Then another folder in the project will serve as API module which is based on Spring Boot. Time being it is a simple application with a RestController and a get mapping.

My module-info for the API module is as follows.

module api_project {
    requires spring.web;  
    requires spring.boot;  
    requires spring.boot.starter.web;  
    requires spring.boot.autoconfigure;  
    opens net.ifao.api to spring.core;  
}

and the gradle dependecies for the API module is as follows

dependencies {  
    implementation project(':ibetms_project')  
    implementation('org.springframework.boot:spring-boot-starter-web') {  
        exclude group: 'org.apache.tomcat.embed', module: 'tomcat-embed-core'  
    }  
    compile "javax.servlet:javax.servlet-api:3.1.0"  
}

If you notice, I exclude the module tomcat-embed-core without which I get 100s of build errors such as

module spring.boot reads package javax.servlet from both javax.servlet.api and org.apache.tomcat.embed.core

this issue helped me about exclusion.

And you can see that I explicitly add javax.servlet-api.3.0.1. But even if I add this or not, I can build the project successfully, but during server start I get following error.

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.

Is it expected? Should I add additional dependency?
I created a sample application for a quick reference. Your help is appreciated?

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: stackoverflowA question that's better suited to stackoverflow.comstatus: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions