@PropertySource:加载指定的配置文件 /** * 将配置文件中配置的每一个属性的值,映射到这个组件中 * @ConfigurationProperties:告诉SpringBoot将本类中的所有属性和配置文件中相关的配置进行绑定: * prefix = "person":配置文件中哪个下面的所有属性进行一一映射 * * 只有这个组件是容器中的组件,才能容器提供的@ConfigurationProperties功能: * @ConfigurationProperties(p…
[从零开始学习Spirng Boot-常见异常汇总] 问题的提出: 我们在开发过程当中,我们可能会碰到这样的问题:No qualifying bean  就是我们定义的bean无法进行注入,那到底是什么原因呢,有时候挺难定位的,当然这个也需要养成良好的编码习惯,这样也会降低出错的几率. 那么一般说是No quanlifying bean很有可能就是我们没有使用注解或者xml注入我们的bean,要么就是我们bean的名称不是我们注入时指定的名称,那么我们就会想如何查看已经载入到spring boo…
@PropertySource注解是将配置文件中 的值赋值给POJO 项目结构如下 一.创建一个Person.Java文件: import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.PropertySource; import org.springframework.stereotype.Component;…
有时候报的错误让你匪夷所思,找错误得学会找根.源头在哪里? 比如:我们刚开始看的错误就是 org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userInfoServiceImpl': Unsatisfied dependency expressed through field 'userInfoRepository'; nested exception…
If you need to access the application arguments that were passed to SpringApplication.run(…​), you can inject a org.springframework.boot.ApplicationArguments bean. The ApplicationArguments interface provides access to both the raw String[] arguments…
方法一 SpringContextUtil public class SpringContextUtil { private static ApplicationContext applicationContext; //获取上下文 public static ApplicationContext getApplicationContext() { return applicationContext; } //设置上下文 public static void setApplicationCont…
1.SpringBoot中加载bean,可以使用注解@compenent直接加载到applicationContext容器中 2.在直接类@Configuration中,手动注册bean,如:…
@**PropertySource**:加载指定的配置文件: ```java /** * 将配置文件中配置的每一个属性的值,映射到这个组件中 * @ConfigurationProperties:告诉SpringBoot将本类中的所有属性和配置文件中相关的配置进行绑定: *      prefix = "person":配置文件中哪个下面的所有属性进行一一映射 * * 只有这个组件是容器中的组件,才能容器提供的@ConfigurationProperties功能: *  @Config…
看起来像最初的问题是与自动配置. 如果你不需要数据源,只需从自动配置过程中删除它: @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})…
从其他框架来看 我们都有自己的配置文件, hibernate有hbm,mybatis 有properties, 同样, Spring boot 也有全局配置文件. Springboot使用一个全局的配置文件,而且配置文件的名字是固定的. 有两种 application.properties application.yml springboot 配置文件的作用是用来 修改SpringBoot自动配置的默认值:SpringBoot在底层都给我们自动配置好: 像我们Tomcat 启动 默认配置端口是8…