& lt;项目xmlns=" http://maven.apache.org/POM/4.0.0 " xmlns: xsi=" http://www.w3.org/2001/XMLSchema-instance " xsi: schemaLocation=" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd "在
,& lt; modelVersion> 4.0.0
,& lt; groupId> springstart
,,
,& lt; artifactId> com.zcp.springstart
,& lt; version> 1.0.0
,& lt; packaging> jar
,,
,& lt; !——方式一:依赖父工程——在
,& lt; !- & lt; parent>
,,& lt; groupId> org.springframework.boot
,,& lt; artifactId> spring-boot-starter-parent
,,& lt; version> 1.5.8.RELEASE
, & lt;/parent>——在
,,
,,
,& lt; properties>
,& lt; project.bulid.sourceEncoding> UTF-8
, & lt; maven.compiler.source> 1.7 & lt;/maven.compiler.source>
, & lt; maven.compiler.target> 1.7 & lt;/maven.compiler.target>
,& lt;/properties>
,,
,,
,& lt; !——方式二:配置这个依赖——在
,& lt; dependencyManagement>
,& lt; dependencies>
,,& lt; !——https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-dependencies——在
& lt; dependency>
,,& lt; groupId> org.springframework.boot
,,& lt; artifactId> spring-boot-dependencies
,,& lt; version> 1.5.8.RELEASE
,,& lt; type> pom
,,& lt; scope> import
& lt;/dependency>
,,
,& lt;/dependencies>
,& lt;/dependencyManagement>
,,
,,
,,
,& lt; dependencies>
,,& lt; dependency>
,,,,& lt; groupId> org.springframework.boot
,,,,& lt; artifactId> spring-boot-starter
,,& lt;/dependency>
& lt;/dependencies>
& lt;/project>
弹簧引导的启动入口的方式
包com.zcp.springstart;
进口org.springframework.boot.SpringApplication;进口org.springframework.boot.autoconfigure.SpringBootApplication;
进口org.springframework.context.ConfigurableApplicationContext;进口org.springframework.context.annotation.Bean;
@SpringBootApplication
公共类应用{
@ bean
公共Runnable createRunnable () {
返回新Runnable () {
@Override
公共空运行(){
System.out.println(“在在在在在在在在在在在在runn - - - - - - - - - - - -”);}
};
}
公共静态void main (String [] args) {
=SpringApplication.run ConfigurableApplicationContext上下文(App.class, args);
context.getBean (Runnable.class) .run ();}
}
说明:springboot的启动入口类,默认为配置类,故可以在该类中注入bean。