【springbootbase模块】上述做法在开发中是不被推荐的,以为现在为止毕竟是两块程序类,这两个彼此之间的联系需要有一个连接点,而程序中配置的“ComponentScan”就是负责这个连接处理,但是SpringBoot考虑到了此类的配置问题,所以提出了一个更简化的策略,该策略的核心思想:既然程序主类会在所有开发包的父包里面,那么能不能简化点去的配置呢?为此在实际的开发之中,会使用一个特殊的符合注解。
package com.gwolf;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
//@EnableAutoConfiguration
//@ComponentScan("com.gwolf.controller")
@SpringBootApplication //启动SpringBoot程序,而后自带子包扫描。
public class SampleController {
public static void main(String[] args) {
SpringApplication.run(SampleController.class, args);
}
}