Spring Boot 注解启动的两种方式

1.@configuration @EnabeAutoConfiguration @ComponentScan
package com.example.myproject;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {

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

}
2.@SpringBootApplication
package com.my.data.cache;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
 * 项目启动器
 * @author wangbowen
 *
 */
@SpringBootApplication//必须标注该注解才能扫描程序里面的注解组件
public class SimpleApplication  implements CommandLineRunner{

	@Override
	public void run(String... args) throws Exception {
		System.out.println("hello!Spring Boot");
	}

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

你可能感兴趣的:(Spring,Boot)