背景介绍
简化配置,更简单的使用spring和第三方软件
springboot官网介绍可以看出springboot的特点
Features
-
Create stand-alone Spring applications/一站式的spring使用
-
Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)/整合了tomcat等容器
-
Provide opinionated 'starter' dependencies to simplify your build configuration/使用starter简化配置
-
Automatically configure Spring and 3rd party libraries whenever possible/自动装配spring和第三方
-
Provide production-ready features such as metrics, health checks and externalized configuration/准生产级别的监控等等
-
Absolutely no code generation and no requirement for XML configuration/没有code生成,没有xml配置
3.常见问题
1)springboot联合mybatis配置文件
2)自动注入时could not autowired
3)springboot测试
4.解决方案
1)在创建时选择mybaits,或者在pom中添加mybatis的starter,
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
在application.properties(或yml)中添加mybatis和datasourse的配置
mybatis.mapper-locations=classpath:*.xml
spring.datasource.driver-class-name=
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
注意名字不要选择错误 这样就完成了基本配置
2)自动注入时could not autowired
会提示错误,但并不影响运行,如果要修改的话,可以使用构造方法注入,或者在原类上添加@component注解
3)springboot测试
springmvc需要加载上下文才能进行某些测试,springboot测试变得简单只需要添加两个注释即可运行spring测试
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
5.编码实战
6.扩展思考
springboot页面制作及其他如redis等等的结合,将springboot用于实战
7.参考文献
博客:纯洁的微笑
http://www.ityouknow.com/spring-boot.html
8.更多讨论
springboot和springcloud结合使用