表示当前pom文件从spring-boot-starter-parent继承下来,在spring-boot-starter-parent中提供了很多默认配置,可以简化我们的开发。

  • Java版本和编码方式

<properties>
   <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
   <java.version>1.8</java.version>
   <resource.delimiter>@</resource.delimiter>
   <maven.compiler.source>${java.version}</maven.compiler.source>
   <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   <maven.compiler.target>${java.version}</maven.compiler.target></properties>
  • 依赖管理spring-boot-dependencies

<properties>
   <activemq.version>5.15.9</activemq.version>
   <antlr2.version>2.7.7</antlr2.version>
   <appengine-sdk.version>1.9.73</appengine-sdk.version>
   <artemis.version>2.6.4</artemis.version>
   ...</properties>

官网说明文档见:13.2.2 Using Spring Boot without the Parent POM

<dependencyManagement>
  <dependencies>
     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>2.1.4.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
     </dependency>
  </dependencies></dependencyManagement>

1.3 Starters

thirdpartyproject-spring-boot-starter

  • spring-boot-web-starter

2.1 @SpringBootApplication

2.2 SpringApplication.run

3.1 初步感受

server.port=9090

3.3 给属性注入值

  • 实体类Person和IDCard

public class Person {    private String name;    private int age;    private Date birthday;    private String[] hobbies;    private IDCard idCard;
   ...
}
public class IDCard {    private int id;    private String number;
}
  • yml注入写法

person:
name: Jack
age: 17
birthday: 1997/06/01
hobbies: [code,sing,share]
idCard:
id: 1
number: 111
  • Person类增加注解

@Component@ConfigurationProperties(prefix="person")
  • 测试

@Autowiredprivate Person person;

4.1 动态资源

4.2 静态资源

  • static文件夹

观察

@ConfigurationProperties(prefix = "spring.resources", ignoreUnknownFields = false)public class ResourceProperties {

5.1 需求

重温一下web项目创建的过程。

db_gupao_springboot--->t_user

5.7 开发service层

@Servicepublic class UserService {    @Autowired
   public UserMapper userMapper;    public User findByUsername(String username){        return userMapper.find(username);
   }    public List<User> listUser(){        return userMapper.list();
   }    public int insertUser(User user){        return userMapper.insert(user);
   }    public int updateUser(User user){        return userMapper.update(user);
   }    public int delete(int id){        return userMapper.delete(id);
   }
}

5.10 application.properties文件配置

#数据源
spring:
 datasource:
   url: jdbc:mysql://127.0.0.1:3306/boot?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
   username: root
   password: 123456
   driver-class-name: com.mysql.cj.jdbc.Driver
#mybatis托管mapper文件
mybatis:
 mapper-locations: classpath:mapper/*.xml

http://localhost:8888/user/listall

  • 增加

http://localhost:8888/user/delete?id=3

java -jar xxx.jar

  • war包

<groupId>com.csdn</groupId><artifactId>springboot-demo2</artifactId><version>0.0.1-SNAPSHOT</version><packaging>war</packaging>

7.1 IDEA创建工程

dependencies:Reactive Web,Reactive MongoDB,Lombok,Actuator,Security

7.3 REST

@SpringBootApplicationpublic class BootifulApplication {    @Bean
   RouterFunction<ServerResponse> routes(CustomerRepository cr){        return RouterFunctions.route(GET("/customers"),serverRequest -> ok().body(cr.findAll(),Customer.class));
   }    public static void main(String[] args) {
       SpringApplication.run(BootifulApplication.class, args);
   }

}

Spring Boot featurese strong opinions,loosely held.

It's easy to change any of them with properties or pluggable implementations

management.endpoint.health.show-details=always
management.endpoints.web.exposure.exclude=*
@BeanHealthIndicator healthIndicator(){return () -> Health.status("I <3 Production").build();
}

Effortlessly plugin authentication and authorization in a traditional or reactive application with Spring Security

@BeanMapReactiveUserDetailsService users(){    return new MapReactiveUserDetailsService(User.withDefaultPasswordEncoder().username("user").password("pw").roles("USER").build());
}

Let's provision a MongoDB instance,configure our application's route and MongoDB binding,and then push our application to production with Cloud Foundry.

定位到my-mongodb文件夹

  • 复制对应文件,修改和观察

关于Spring Boot你不得不知道的事--Spring Boot的基本操作_Spring Boot