简体   繁体   中英

Spring boot. Mapping 2 seperate project controllers ignoring a project

I have a spring boot application, that loads the configurations of 2 other projects as follows:

The application annotation: @ImportResource("path/to/xml/config.xml")

Which maps to the config.xml containing :

<import resource="classpath:path/to/project1/config.xml"/>
<import resource="classpath:path/to/project2/config.xml"/>

These config.xml's contain the following lines respectively :

<context:component-scan base-package="my.project1.package" />
<context:component-scan base-package="my.project2.package" />

Within those packages I have a controller:

Project 1 controller

package my.project1.package;

@RestController
@RequestMapping("/project1")
@SessionAttributes("batchNumber")
public class Project1Controller { 
    @RequestMapping(value="/sample", method = RequestMethod.GET)
    public String sampleMethod() {
        return "hi";
    }
}

and Project 2 controller:

package my.project2.package;

@RestController
@RequestMapping("/project2")
@SessionAttributes("batchNumber")
public class Project2Controller { 
    @RequestMapping(value="/sample", method = RequestMethod.GET)
    public String sampleMethod() {
        return "hi2";
    }
}

Yes, the method names and their mappings need to be the same, only the class's ReqeustMapping is different.

When I start my application using Spring Boot.

I get the Mapped [/project1/sample] line which works fine, however the /project2/sample never gets mapped.

Is there a possible reason why these controllers aren't getting mapped/scanned?

As in the comments above

Had a wrong package listed in the context scan

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM