Using different packages for controllers when using Spring

If I create a standard Spring project from spring tools, it works great!

I visit localhost:8080/greetingand get an answer hello world.

If I copy these 2 files to another package in my source tree and then go to localhost:8080/greeting, I will get:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Oct 17 18:15:45 BST 2014
There was an unexpected error (type=Not Found, status=404).

Moving 3 classes to the same package by default fixes the problem, but from the point of view of organizing the source tree, this is not what I want to do.

I expect this to be due to some auto-configuration, so please someone can tell me what I have to do so that my project can support multiple packages as controllers and objects.

+7
2

, servlet-context.xml

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

. .

Update:

XML.

"Spring Boot App", . , @ComponentScan. AppConfig.

, . , :

@ComponentScan({ "x.y.z.services", "x.y.z.controllers" })
+15

, main com.setech.app, com.setech.controller.

Spring-boot 1.3.x , "scanBasePackages" .

@SpringBootApplication(scanBasePackages = { "com.setech"} )
public class ResttanslatorApplication {

    public static void main(String[] args) {

        SpringApplication.run(ResttanslatorApplication.class, args);
    }
}

.

0

All Articles