spring-boot-starter-parent簡介:
1,包含了常用版本屬性;
要修改java編譯版本,可以修改: <properties> <java.version>1.7</java.version> </properties>
2,包含了常用的dependenceManagement;
3,SpringBoot非常優秀的地方在於提供了非常多以spring-boot-starter-*開頭的開箱即用的工具包,常見工具包有以下一些:
spring-boot-starter:核心的工具包,提供了自動配置的支持,日誌和YAML配置支持;
spring-boot-starter-activemq:針對快速集成ActiveMQ的工具包;
spring-boot-starter-aop:提供了快速集成SpringAOP和AspectJ的工具包;
spring-boot-starter-data-redis:提供了快速集成Redis和Jedis的工具包;
spring-boot-starter-freemarker:提供了快速集成Freemarker的工具包;
spring-boot-starter-mail:提供了快速集成郵件發送的工具包;
spring-boot-starter-test:提供了對Springboot應用的測試工具包;
spring-boot-starter-web:提供了對web開發的工具包,包括基於SpringMVC的RESTful應用開發,內置的tomcat服務器等;
spring-boot-starter-actuator:提供了對生產環境中應用監控的工具包;
spring-boot-starter-logging:提供了對日誌的工具包,默認使用Logback;
1 ) 添加相關依賴.
1.1 添加Druid的依賴.
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.4</version>
</dependency>
1.2 添加mysql連接驅動依賴.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
1.3 添加jdbc依賴.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
注意:這裏的Druid的依賴適用於SpringBoot1.X版本,如果用上2.X版本可能會出現如下錯誤,2.X需要用druid1.1.10
2 )創建DataSource對象
方式一:
2.1)在配置文件中添加數據庫相關的配置.
2.2)
2.3)
方式二:
2.1 )在配置文件中添加如下配置.屬性配置需要按spring.datasource.druid開頭.(具體屬性參考DruidDataSource)
2.2) 不需要在配置類中創建Bean了.
2.3) 測試是否創建數據庫連接池對象.