起因:在公司都是现成都东西,对springboot理解没办法很深入。所以自己来搭建框架玩一玩。
参考:https://blog.csdn.net/alantuling_jt/article/details/54893383
1、在application.properties文件添加配置:
server.port = 1010
spring.datasource.url = jdbc:mysql://localhost:3306/Alexchs?characterEncoding=utf8&useSSL=true
spring.datasource.username = root
spring.datasource.password = 123456
spring.datasource.driverClassName = com.mysql.jdbc.Driver
2、搭建demo教程:http://tengj.top/2017/02/26/springboot1/
3、集成MyBatis框架,在连接数据库的时候,用到的是mysql-connector-java 6.0.5:
- 需要注意jdbc的配置,参考https://www.jianshu.com/p/83c1d1f654fb
<mysql-connector-java.version>6.0.5</mysql-connector-java.version>
搭建问题记载:
- 加载中报错:由于pom配置中parent和dependecyManagement中配置了不一样版本的相同启动依赖导致该问题。于是简单看了一下maven的scope、parent和dependencyManagement。
ERROR org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroy method on bean with name 'org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory' threw an exception
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@4233e892: startup date [Thu Nov 29 16:55:00 CST 2018]; root of context hierarchy
Error creating bean with name 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
<parent>
<!--C:\Users\用户.m2\repository\org\springframework\boot\spring-boot-dependencies\1.5.1.RELEASE\spring-boot-dependencies-1.5.1.RELEASE.pom-->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencyManagement>
<dependencies>
<!-- Override Spring Data release train provided by Spring Boot -->
<!--<dependency>-->
<!--<groupId>org.springframework.data</groupId>-->
<!--<artifactId>spring-data-releasetrain</artifactId>-->
<!--<version>Fowler-SR2</version>-->
<!--<scope>import</scope>-->
<!--<type>pom</type>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-dependencies</artifactId>-->
<!--<version>1.5.1.RELEASE</version>-->
<!--<type>pom</type>-->
<!--<scope>import</scope>-->
<!--</dependency>-->
</dependencies>
</dependencyManagement>
- 引入Swagger2报错,情况如:https://blog.csdn.net/u011781521/article/details/79726599
需要在Application.class添加@EnableSwagger2注解
- 在刚搭建的时候,会报APR版本过低的错,参考:https://blog.csdn.net/Soap_Leutenant/article/details/79632613
- 分别在application.yml和application.properties文件中添加相同配置,最后生效的是application.properties中的配置。
blog问题:
1、插入代码本身
2、过于简略