旧时咱们开发一个普通spring的项目时,会存在很难麻烦的xml配置过程java
如今,有了springboot,大大减小配置时间,一键启动, 方便又快捷mysql
没了 就是这么简单web
下面咱们具体说说redis
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <!--mybatis 开发包--> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.2</version> </dependency> <!--springboot web模块支持--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <!--druid 的数据源--> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.0.31</version> </dependency>
spring-boot-starter-web包自动帮咱们引入了web模块开发须要的相关jar包,spring
mybatis-spring-boot-starter帮咱们引入了dao开发相关的jar包。sql
spring-boot-starter-xxx是官方提供的starter,xxx-spring-boot-starter是第三方提供的starter。数据库
spring: datasource: url: jdbc:mysql://127.0.0.1:3306/mybatis_test username: root password: root driver-class-name: com.mysql.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource dbcp2: min-idle: 5 initial-size: 5 max-total: 5 max-wait-millis: 200
@SpringBootApplication public class SpringbootMybatisDemoApplication { public static void main(String[] args) { SpringApplication.run(SpringbootMybatisDemoApplication.class, args); } }
@SpringBootApplication:包含了@ComponentScan、@Configuration和@EnableAutoConfiguration注解。其中@ComponentScan让spring Boot扫描到Configuration类并把它加入到程序上下文。tomcat
@Configuration 等同于spring的XML配置文件;使用Java代码能够检查类型安全。安全
@EnableAutoConfiguration 自动配置。springboot
@ComponentScan 组件扫描,可自动发现和装配一些Bean。
@Component可配合CommandLineRunner使用,在程序启动后执行一些基础任务。
@RestController注解是@Controller和@ResponseBody的合集,表示这是个控制器bean,而且是将函数的返回值直 接填入HTTP响应体中,是REST风格的控制器。
@Autowired自动导入。
@PathVariable获取参数。
@JsonBackReference解决嵌套外链问题。
@RepositoryRestResourcepublic配合spring-boot-starter-data-rest使用。