




spring-boot-starter-parent org.springframework.boot 2.5.3 org.springframework.boot spring-boot-starter-web


package com.sun.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author 孙显圣
* @version 1.0
*/
//表示是一个springboot项目
@SpringBootApplication
public class MainApp {
public static void main(String[] args) {
//启动springboot
SpringApplication.run(MainApp.class, args);
}
}
package com.sun.springboot.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @author 孙显圣
* @version 1.0
*/
@Controller //仍然是spring注解
public class HelloController {
@ResponseBody
@RequestMapping("/hello")
public String hello() {
return "hello, springboot";
}
}
































#端口号 server.port=10000 #应用的上下文路径(项目路径) server.servlet.context-path=/allModel #指定 POJO 扫描包来让 mybatis 自动扫描到自定义的 POJO mybatis.type-aliases-package=com.cxs.allmodel.model #指定 mapper.xml 的路径 #(application 上配置了@MapperScan(扫面 mapper 类的路径)和 pom.xml 中放行了 mapper.xml 后, # 配 置 mapper-locations 没 有 意 义 。 如 果 mapper 类 和 mapper.xml 不 在 同 一 个 路 径 下 时 , mapper-locations 就有用了) mybatis.mapper-locations=classpath:com/cxs/allmodel/mapper #session 失效时间(单位 s) spring.session.timeout=18000 #数据库连接配置 #mysql 数据库 url mysql.one.jdbc-url=jdbc:mysql://127.0.0.1:3306/test?serverTimezone=Asia/Shanghai&useSSL=false #mysql 数据库用户名 mysql.one.username= #数据库密码 mysql.one.password= #线程池允许的最大连接数 mysql.one.maximum-pool-size=15 #日志打印:日志级别 trace7.解读SpringBoot是从哪里读取的配置文件
ctrl + n 进入ConfigFileApplicationListener
8.按需加载原则
1.基本介绍
2.autoconfigure包管理着所有的starter
9.关于xxxAutoConfiguration,xxxProperties,application.properties的关系
1.简要介绍
- xxxProperties这个单例bean的属性就是配置,读取application.properties来修改默认的配置
- xxxAutoConfiguration这个单例bean的属性中有xxxProperties,通过依赖注入获取到xxxProperties的bean对象从而实现自动装配
2.查看源码
3.debug展示ioc容器
上一篇:mysql开启远程访问权限