org.springframework.boot spring-boot-starter-parent2.5.5
它自身还有一个叫做spring-boot-dependencies的父项目
org.springframework.boot spring-boot-dependencies2.5.5
父项目中又管理着很多版本号。
2、spring项目创建的时候会自动依赖spring-boot-starter-web,该模块自动引入了Tomcat和springMCV3、主程序所在的包默认都会被扫描
但是我们也可以另外可以至指定扫描包
一、在SpringbootApplication上加scanbasePackages
@SpringBootApplication(scanbasePackages = "com.example")
//==============================================
二、或者注释掉@SpringbootApplication,然后换成下面三个:
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan("com.example")
4、可以再application.properties这个文件下开启debug模式,然后他就会自动打印引入的具体场景了,哪些生效Positive,哪些未生效有会打印Negative。
debug=true5、application.yml要配置什么东西都可以再这里进行查找Common Application Properties 6、通过@Bean和@Component来自定义组件 7、yml配置文件和java bean相互绑定
1)首先要在Bean类中注解@Component和@ConfigurationProperties(prefix="myuser"),这是绑定的关键,而且bean中必须要有set和get方法
@ConfigurationProperties(prefix="myuser")
@Component
public class User {
private String myUserName;
private int myAge;
private String address;
private ArrayList friends;
private HashMap myMap;
//此处省略set和get方法
}
2)yml的开头要和bean中指定的prefix指定的一致,这里使用的是myuser
myuser:
my-age: 32
my-user-name: "唐僧"
address: "大宋"
friends: ["孙悟空", "猪八戒", "沙僧"]
my-map:
name: "牛魔王"
age: 33
3)为了在编辑yml文件的时候有提示,我们还要加入
org.springframework.boot
spring-boot-configuration-processor
true
但是这个包不应该在打包的时候参与打包,所以通过excludes排除掉
8、为静态资源加前缀
spring:
mvc:
static-path-pattern: /myresource@RequestParam Map p){
return p.toString();
}
请求方式:http://localhost/req?id1=99&&name=张三
3)POST参数@RequestBodys
@PostMapping("/getPost")
public String getPost(@RequestBody String p){
return "Post参数:"+p;
}
11、如果自定义了WebMvcConfigurer了,并且加了@EnableWebMvc,则Springboot所有自动配置都将会失效,需要手动自己写
12、自动配置原理套路分析:
引入starter——>xxxAutoConfiguration——>导入xxx组件——>绑定xxxProperties——>绑定配置文件
所以需要修改相关配置要倒过来,先修改配置文件,如果不行就只能一步步的回溯上去,自定义相关Properties或者是组件,从而达到自定义的效果。



