简体   繁体   English

Spring Boot 如何找到控制器包?

[英]How does Spring Boot find the controller package?

I'm studying Spring Boot from a sample project.我正在从一个示例项目中学习 Spring Boot。 It has application like below.它有如下应用。

@SpringBootApplication
public class PayApplication {

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

}

and in controller package there is a controller.在控制器包中有一个控制器。

@Controller
@RequestMapping("/")
public class LoginController {
    @GetMapping("/")

And an index.html in template.和模板中的 index.html。
I'm still confused in how the run method find the controller package?And at where the index.html is set as default page?我仍然对 run 方法如何找到控制器包感到困惑?在 index.html 设置为默认页面的位置? Any help?有什么帮助吗? Thx.谢谢。

The annotation @Controller allows to auto-detect implementation classes through the classpath scanning.注解@Controller 允许通过类路径扫描自动检测实现类。 It tells Spring that your class is a component of type Controller.它告诉 Spring 你的类是 Controller 类型的组件。

Depending on configurations(InternalResourceViewResolver is responsible as default if no configurations is done at all, see below the picture) the default behavior of the view resolver is described below(from Pivotal Certified Professional chapter6):根据配置(InternalResourceViewResolver 负责默认,如果根本没有配置,见下图)视图解析器的默认行为描述如下(来自 Pivotal Certified Professional 第 6 章):

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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