![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
Spring
以Spring系列为主
youshang520i
不忘初心,方得始终
展开
-
在Spring boot 项目中想要在项目启动完成进行一些操作(CommandLineRunner)
推荐实现CommandLineRunner使用方法:自定义Class 通过@Component标识,如果有多个CommandLineRunner 的实现类,可以通过@Order 去区分优先级比较 @PostConstruct VS 实现CommandLineRunner1. @PostConstruct 在服务器加载Servlet的时候运行,init()之后执行,PreDestroy()之前执行2. 实现CommandLineRunner 在Spring Boot服务启动完成之后执行/**原创 2021-09-15 17:28:10 · 123 阅读 · 0 评论 -
Spring 项目中将resources目录下的.xml文件导入项目中
使用背景:在特殊的业务场景下需要配合.xml文件进行对象操作使用方式:@ImportResource(value = "classpath:/springBean.xml")使用@ImportResource注解将.xml文件导入项目中@ComponentScan(value = {"com.bunnymaicai.boot.kafka"})@SpringBootApplication@ImportResource(value = "classpath:/springBean.xml原创 2021-02-28 22:56:23 · 893 阅读 · 1 评论 -
Spring boot读取自定义的配置文件
比如我在项目中的resources目录下新建了一个mysql.properties文件此时需要读取当前文件怎么办???可以使用@PropertySource(value="classpath:/mysql.properties")配合@Configuration 进行配置,通过Environment读取/** * * @author youshang * @date 2021/02/26 16:29 **/@PropertySource(value = "classpath:/mysql原创 2021-02-26 19:00:28 · 409 阅读 · 0 评论 -
@Configuration和@Conditional同时存在的时候导致@Configuration下的Bean失效
本文涉及到的关注点1. 项目中存在MyConfig和MyConfig2这两个本文中是实验对象2. 自定义OnBeanCondition 实现Condition ,通过特定条件执行特定的需求3.Mybean和Mybean2 充当本文中的路人甲,乙4.ConfigurationCondition充当本文中的幕后 King5.项目结构目录,扫描的也是启动文件的当前目录1. 咋们先来看看两个实验对象import com.youshang520i.demo.LocalCond..原创 2021-02-26 18:08:18 · 1142 阅读 · 1 评论 -
关于Spring @Configuration注解的full和lite模式导致事务没办法回滚
1.先说说在使用这个注解的时候遇到的问题吧!!!在学习Spring transaction的时候想要实现遇到报错然后回滚,结果总是回滚失败!!最后请求大佬支援看到了我的傻逼问题我先说说我的傻逼问题,我把@Configuration写成了@Configurable 然后在代码中使用的是:@Configurable//这是错误的 应该改成@Configuration@ComponentScan("com.youshang520i")@EnableTransactionManagement@M原创 2021-02-25 18:10:57 · 291 阅读 · 0 评论 -
Spring 源码中的重点注解(日后会经常更新)
@EventListener注解使用的底层实现类:EventListenerMethodProcessor原创 2021-02-20 18:14:14 · 119 阅读 · 0 评论 -
Mac构建Spring Boot 源码
报错信息:1.[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project spring-boot-test-support: Compilation failure[ERROR] No compiler is provided in this environment. Perhaps you are runnin原创 2021-02-03 15:41:27 · 266 阅读 · 0 评论 -
Idea运行SSM项目报错:Ambiguous mapping. Cannot map 'XXController' method
报错信息是因为重名了RequestMapper比如有一个RequestMapper("/person/index")另外一个页面也有RequestMapper("/index")就会报错Ambiguous mapping. Cannot map 'XXXController' method之前在Eclipse的时候 没有遇到过。。刚刚用Idea还有很多不熟。日后来提供更多的答案...原创 2019-02-28 09:33:27 · 328 阅读 · 0 评论 -
Spring 项目中报错提示:Invalid bound statement (not found): com.youshang520i.**.**] with root cause
报错信息:2020-09-25 10:23:13.834 ERROR 1539 --- [nio-8008-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache原创 2020-09-25 11:21:24 · 6805 阅读 · 3 评论 -
spring boot 启动报错org.apache.catalina.LifecycleException: Protocol handler start failed
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\_...原创 2019-02-23 18:47:06 · 14049 阅读 · 5 评论 -
Spring Boot配置多数据源
1. 在application.properties中添加多个数据源的配置#数据源一master.datasource.url=jdbc:mysql://***.**.***.**:****/数据库?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTCmaster.datasource.username=...原创 2019-07-31 15:37:45 · 286 阅读 · 0 评论 -
Spring 使用 AopConfigUtils.registerAutoProxyCreatorIfNecessary(registry); 注册代理
原先有问题的代码自定义注解@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.TYPE)@Documented@Import(RateLimiterImportBeanDefinitionRegistrar.class)public @interface EnableRateLimiter { /** * 扫描路径 * @return */ boolean proxyTargetClass原创 2020-12-21 18:58:08 · 516 阅读 · 0 评论 -
Spring源码工具收集
根据你传进来的basePackage路径获取当前路径下面的所有classString basePackage = "com.youshang520i";//拼接成指定的表达式:classpath*:com/youshang520i/**/*.classString packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resolveBasePackage(basePackage) + '/' + t原创 2020-11-25 16:18:51 · 181 阅读 · 0 评论 -
Spring 使用自定义注解 + Cglib + RateLimiter进行限流操作
当前项目的作用,可以生成一个对应的Jar包丢进项目中,然后引用对应的注解@EnableRateLimiter 表示全局开启 限流,在接口上面使用@RateLimiter 添加对应的参数实现限流操作有什么问题欢迎讨论git@gitee.com:liaojuhui/spring-cglib-ratelimiter.git...原创 2020-11-11 17:26:19 · 282 阅读 · 0 评论 -
Spring boot 通过 @ConfigurationProperties获取属性
假设配置文件的属性是这样的。。spring: cloud: consul: config: enabled: true #enabled 设置config是否启用,默认为true format: yaml #format 设置配置的值的格式,可以yaml和properties prefix: config原创 2020-07-27 14:56:41 · 483 阅读 · 0 评论 -
Spring初始化Bean的三种形式
大致使用这三种方式BeanPostProcessor@PostConstruct @PreDestroyinitMenthod DestroyBeanPostProcessor 两个方法 postProcessBeforeInitialization postProcessAfterInitialization@PostConstruct 和 postProcessBeforeInitializationpostProcessBeforeInitialization 在 @PostCons.原创 2020-06-29 09:21:54 · 2614 阅读 · 0 评论 -
什么是动态代理?Spring中有哪几种实现?有什么区别?
什么是动态代理?Spring中有哪几种实现?有什么区别?答: 1.可以任意的控制任意对象的执行过程,这个对象的执行过程可以由客户端灵活的指定 2. 两种 3.jdk和CGLibJDK 1. JDK version <= 1.6 的时候实现InvocationHandler,重写invoke,自定义初始化对象(method.invoke(Object,args)) 2.利用拦截器(必须要实现InvocationHandler接口)加上反射机制生成一个代理接口的匿名类,在..原创 2020-06-29 09:02:03 · 1209 阅读 · 0 评论 -
本地构建Spring源码步骤
1. 通过gitee(码云去拉取代码)原创 2020-06-19 09:04:38 · 484 阅读 · 0 评论 -
Spring Boot中启动Tomcat报错Error starting ApplicationContext. To display the conditions report re-run you
Spring Boot中1.5.6所需要的依赖和2.1.0所需要的依赖是不一样的,如果使用同版本的依赖会导致版本冲突报错信息:报错原因:版本冲突Spring Boot1.5.6所需要的基础依赖: <parent> <groupId>org.springframework.boot</groupId> <artif...原创 2018-11-08 19:57:15 · 17181 阅读 · 15 评论 -
Spring Boot第一次创建报错 'url' attribute is not specified and no embedded
报错信息:Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.2018-11-08 19:29:51.900 ERROR 14920 --- [ main] o.s.b.d.LoggingFai...原创 2018-11-08 19:35:31 · 337 阅读 · 0 评论 -
eureka-config-client @Value找不到注册中心的配置信息
报错信息:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'eurekaConfigClientApplication': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholde原创 2020-07-07 18:58:10 · 482 阅读 · 2 评论 -
Spring cloud 集成 seata 报错信息
2020-09-02 11:30:36.253 INFO 4237 --- [ main] io.seata.core.rpc.netty.RmRpcClient : RM will register :jdbc:mysql://192.168.3.123:3306/seata2020-09-02 11:30:36.254 INFO 4237 --- [ main] i.s.core.rpc.netty.NettyPoolableFactory :.原创 2020-09-02 11:40:15 · 5341 阅读 · 0 评论