springboot中Hello World Application的探究是怎样的
springboot中Hello World Application的探究是怎样的,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
1. POM文件
1. 父项目
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> </parent> spring-boot-starter-parent的父项目: <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>1.5.9.RELEASE</version> <relativePath>../../spring-boot-dependencies</relativePath> </parent> spring-boot-dependencies真正来管理Spring Boot项目中所有的依赖版本
Spring Boot的版本仲裁中心,以后我们导入依赖默认不需要写版本(没有在spring-boot-dependencies中的依赖就需要声明版本号)
2. 导入的依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
spring-boot-starter-web :
spring-boot-starter: spring boot场景启动器
2. 主程序类,主入口类
/** * @SpringBootApplication 来标注一个主程序类,说明这是一个Spring boot应用 */ @SpringBootApplication public class HelloWorldMainApplication { public static void main(String[] args) { //启动Spring应用 SpringApplication.run(HelloWorldMainApplication.class, args); } }
@SpringBootApplication: Spring Boot应用注解,标注在某个类上说明这是Spring Boot应用的主入口类,SpringBoot就应该运行这个类的main方法来启动应用SpringBoot应用
@SpringBootAppliation:
@Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @SpringBootConfiguration @EnableAutoConfiguration @ComponentScan( excludeFilters = {@Filter( type = FilterType.CUSTOM, classes = {TypeExcludeFilter.class} ), @Filter( type = FilterType.CUSTOM, classes = {AutoConfigurationExcludeFilter.class} )} ) public @interface SpringBootApplication { @AliasFor( annotation = EnableAutoConfiguration.class, attribute = "exclude" ) Class<?>[] exclude() default {}; @AliasFor( annotation = EnableAutoConfiguration.class, attribute = "excludeName" ) String[] excludeName() default {}; @AliasFor( annotation = ComponentScan.class, attribute = "basePackages" ) String[] scanBasePackages() default {}; @AliasFor( annotation = ComponentScan.class, attribute = "basePackageClasses" ) Class<?>[] scanBasePackageClasses() default {}; }
@SpringBootConfiguration:
SpringBoot的配置类,标准在某个类上,表示这是一个SpringBoot的配置类
@Configuration:配置类(配置文件) -- 也是一个组件Component
@EnableAutoConfiguration:
开启自动配置功能
看完上述内容,你们掌握springboot中Hello World Application的探究是怎样的的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!