Spring Boot startup configuration articles
(The project is managed by maven)
After using Spring Boot for a period of time, I found that Spring Boot is indeed very convenient and fast. The built-in Tomcat and hot deployment can greatly improve the development efficiency of web projects.
Comparing Spring Boot with Spring, Spring Boot simplifies a large number of xml files that Spring needs to configure in the form of annotations, leaving only one application.yml, and can also easily integrate other frameworks
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<!-- dependencies所需的dependency -->
<!-- 数据库连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.5</version>
</dependency>
<!-- 使用mysql,必须加,否则无法使用mysql,版本号不需要加 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- 测试用 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- web支持配置 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- tomcat启动配置 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- 热部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<!-- 插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- maven执行install时不指定单元测试 -->
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- 热部署开启-->
<fork>true</fork>
</configuration>
</plugin>
application.yml
spring:
#spring mvc的配置,使用jsp需要用到
#mvc:
#view:
#prefix:
#suffix:
#数据源
datasource:
url: jdbc:mysql://localhost/student?useUnicode=true&characterEncoding=UTF-8&useSSL=true
username:
password:
driver-class-name: com.mysql.jdbc.Driver
# 使用druid 数据源,数据库连接池
type: com.alibaba.druid.pool.DruidDataSource
dbcp2:
min-idle: 1
max-idle: 2
initial-size: 1
time-between-eviction-runs-millis: 3000
min-evictable-idle-time-millis: 300000
#validation-query: SELECT "ZTM" FROM DUAL
test-while-idle: true
test-on-borrow: false
test-on-return: false
Start the class, right-click the class name, and run it directly by Run As Java Application
@SpringBootApplication//标注spring boot的启动入口
@EnableTransactionManagement //打开事务管理功能
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}