Spring Team在现有Spring框架的基础上发布了一个创新的主要框架:Spring Boot。开发Spring Boot的主要动机是简化配置和部署spring应用程序的过程。
Spring Boot为开发提供一个具有最小功能的Spring应用程序,并提供了一个新的范例。使用Spring Boot将能够以更灵活的方式开发Spring应用程序,并且能够通过最小(或可能没有)配置Spring来专注于解决应用程序的功能需求。它使用全新的开发模型,通过避免一些繁琐的开发步骤和样板代码和配置,使Java开发非常容易。
springboot是采用springcloud进行微服务开发的基础。
Spring Boot优点和缺点
1、建立Maven项目,导入spring boot父工程
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.0.1.RELEASE
2、导入Web支持
org.springframework.boot
spring-boot-starter-web
3、编写Controller类
随意一个常用的controller类
例如
/**
* 路由
* author chenxiaozhuang
* 所有菜单都是有用户权限产生的,在新增一个菜单之前必须指出它的访问路径
*/
@Controller
public class NavigateController {
@RequestMapping("/login")
public String test()
{
return "login";
}
@RequestMapping("/userManager.do")
public String userlist()
{
return "userList";
}
4、编写一个启动类
核心加入@SpringBootApplication注解
@SpringBootApplication
//@MapperScan("com.tckj.tckj.user.dao")//扫描xml文件时,必须加入
public class PriorApplication {
public static void main(String[] args) {
SpringApplication.run(PriorApplication.class, args);
}
}
5、引入导入thymeleaf页面模块
org.springframework.boot
spring-boot-starter-thymeleaf
6、另外、根据需要在引入其它jar包,例如一个完成的项目
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.0.1.RELEASE
prior
prior
0.0.1-SNAPSHOT
prior
Demo project for Spring Boot
1.8
org.springframework.boot
spring-boot-starter-web
mysql
mysql-connector-java
5.1.45
org.apache.cxf
cxf-rt-transports-http
3.1.11
org.apache.cxf
cxf-rt-frontend-jaxws
3.1.11
com.fasterxml.jackson.core
jackson-core
2.8.11
com.fasterxml.jackson.core
jackson-annotations
2.8.11
com.fasterxml.jackson.core
jackson-databind
2.8.11
net.sf.json-lib
json-lib
2.4
jdk15
org.apache.commons
commons-lang3
3.6
org.mybatis.spring.boot
mybatis-spring-boot-starter
1.1.1
com.alibaba
druid
1.0.9
org.projectlombok
lombok
org.apache.shiro
shiro-spring
1.4.0
com.github.theborakompanioni
thymeleaf-extras-shiro
2.0.0
org.springframework.boot
spring-boot-starter-thymeleaf
org.springframework.boot
spring-boot-devtools
runtime
true
taglibs
standard
1.1.2
commons-beanutils
commons-beanutils
1.9.3
org.springframework.boot
spring-boot-starter-test
test
org.junit.vintage
junit-vintage-engine
com.vaadin.external.google
android-json
0.0.20131108.vaadin1
compile
org.springframework.boot
spring-boot-maven-plugin
配置文件
两个
application.properties
server.port=9999
spring.datasource.url=jdbc:mysql://localhost:3306/persms
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
mybatis.type-aliases-package=com.itheima.domain
spring.profiles.active=dev
application-dev.properties
server.port=9999
logging.config=classpath:logback1-core.xml
spring.thymeleaf.prefix=classpath:/web/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=LEGACYHTML5
一个springboot项目目录结构