初识SpringBoot

1.引入pom依赖



    4.0.0

    first-boot
    first_boot
    1.0-SNAPSHOT

    
        
        1.8
    
    
    
        org.springframework.boot
        spring-boot-starter-parent
        2.0.1.RELEASE
    
    
        
        
            org.springframework.boot
            spring-boot-starter-web
        
    

    
    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
                2.0.1.RELEASE
                
                    
                        
                            repackage
                        
                    
                
            
        
    



2.创建Application.java类
/**
* @author: krauser
* @date: Create in 下午7:27 2018/4/13
* @Description:
*/
@SpringBootApplication(scanBasePackages = {"org.java.com.*"})
public class Application {

    /**
     * 1.java -jar
     *
     * 2.mvn spring-boot:run
     * @param args
     */
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}


@SpringBootApplication是一个复合注解
public @interface SpringBootApplication {
    @AliasFor(
        annotation = EnableAutoConfiguration.class
    )
    Class[] exclude() default {};

    @AliasFor(
        annotation = EnableAutoConfiguration.class
    )
    String[] excludeName() default {};

    @AliasFor(
        annotation = ComponentScan.class,
        attribute = "basePackages"
    )
    String[] scanBasePackages() default {};

    @AliasFor(
        annotation = ComponentScan.class,
        attribute = "basePackageClasses"
    )
    Class[] scanBasePackageClasses() default {};
}
3.定义一个简单的controller

@RestController
@RequestMapping("/firstboot")
public class FirstBootController {

    @GetMapping(value = "/sayHello")
    public String sayHello(){
        return "this is my first boot grogram!!!";
    }

}
4.现在第三方框架的引入经常会出现jar包冲突,这里有一个查看依赖树的方法,可以查看springboot引入jar包的情况

mvn dependency:tree

[INFO] first-boot:first_boot:jar:1.0-SNAPSHOT
[INFO] \- org.springframework.boot:spring-boot-starter-web:jar:2.0.1.RELEASE:compile
[INFO]    +- org.springframework.boot:spring-boot-starter:jar:2.0.1.RELEASE:compile
[INFO]    |  +- org.springframework.boot:spring-boot:jar:2.0.1.RELEASE:compile
[INFO]    |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.0.1.RELEASE:compile
[INFO]    |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.0.1.RELEASE:compile
[INFO]    |  |  +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO]    |  |  |  +- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO]    |  |  |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO]    |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.10.0:compile
[INFO]    |  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.10.0:compile
[INFO]    |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO]    |  +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO]    |  +- org.springframework:spring-core:jar:5.0.5.RELEASE:compile
[INFO]    |  |  \- org.springframework:spring-jcl:jar:5.0.5.RELEASE:compile
[INFO]    |  \- org.yaml:snakeyaml:jar:1.19:runtime
[INFO]    +- org.springframework.boot:spring-boot-starter-json:jar:2.0.1.RELEASE:compile
[INFO]    |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.5:compile
[INFO]    |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
[INFO]    |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.9.5:compile
[INFO]    |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.5:compile
[INFO]    |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.5:compile
[INFO]    |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.5:compile
[INFO]    +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.0.1.RELEASE:compile
[INFO]    |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.29:compile
[INFO]    |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.29:compile
[INFO]    |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.29:compile
[INFO]    +- org.hibernate.validator:hibernate-validator:jar:6.0.9.Final:compile
[INFO]    |  +- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO]    |  +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
[INFO]    |  \- com.fasterxml:classmate:jar:1.3.4:compile
[INFO]    +- org.springframework:spring-web:jar:5.0.5.RELEASE:compile
[INFO]    |  \- org.springframework:spring-beans:jar:5.0.5.RELEASE:compile
[INFO]    \- org.springframework:spring-webmvc:jar:5.0.5.RELEASE:compile
[INFO]       +- org.springframework:spring-aop:jar:5.0.5.RELEASE:compile
[INFO]       +- org.springframework:spring-context:jar:5.0.5.RELEASE:compile
[INFO]       \- org.springframework:spring-expression:jar:5.0.5.RELEASE:compile

可以看到springboot自动给我们引入了五个包

1. spring-core logback slf4j 

2. tomcat相关包

3. hibernate-validator

4. Jackson

5. spring-web spring-webmvc

你可能感兴趣的:(微服务,springboot,JAVA基础知识)