最代码官方
2021-01-25 23:55:59
证
Spring自定义类似@Required注解实现在容器启动时对bean进行依赖校验
项目描述
上一个代码Spring通过@Required注解实现在容器启动时对bean进行依赖校验
是通过Spring内置的@Required注解实现的bean依赖的校验
这一个代码通过自定义注解实现类似机制
运行环境
jdk8+IntelliJ IDEA+maven
项目技术(必填)
spring+自定义Annotation
依赖包文件(可选)
链接:https://pan.baidu.com/s/1mAmWlS3H3MPmcK7NYxHrvg
提取码:silt
是否原创(转载必填原文地址)
转载https://memorynotfound.com/spring-custom-required-styled-annotation-example/
项目截图(必填)
运行截图(必填)
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'luke' defined in class path resource [app-config.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanInitializationException: Property 'theForce' is required for bean 'luke' at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) at com.memorynotfound.spring.core.required.Main.main(Main.java:9) Caused by: org.springframework.beans.factory.BeanInitializationException: Property 'theForce' is required for bean 'luke' at org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor.postProcessPropertyValues(RequiredAnnotationBeanPostProcessor.java:156) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ... 11 more
注意事项(可选)
运行Main即可
猜你喜欢
- Java Spring的三种注入方式
- Spring自定义日志注解拦截初始化Logger对象实现日志输出的实例
- Spring自定义ThreadLocal Scope实现类:ThreadScope
- spring注解annotation实例demo
- Spring两种常用的事务管理范例AspectJ和基于注解方式
- [工作必备]spring定时器简单的demo
- Spring通过配置component-scan base-package实现自动扫码指定路径的类并初始化bean的简单示例
- Spring生命周期接口InitializingBean和DisposableBean的实例演示
- spring通过@Async注解实现异步执行Service方法并且通过Java Future对象得到执行结果
- spring通过p-namespace的方式实现xml配置bean的属性实例
- spring通过c-namespace的方式实现xml配置bean构造函数实例
- Spring通过properties文件的配置实现bean初始化的简单示例
请下载代码后再发表评论
文件名:custom-spring-@required-annotation-example.zip,文件大小:6.409K
下载
- /
- /custom-spring-@required-annotation-example
- /custom-spring-@required-annotation-example/pom.xml
- /custom-spring-@required-annotation-example/src
- /custom-spring-@required-annotation-example/src/.DS_Store
- /custom-spring-@required-annotation-example/src/main
- /custom-spring-@required-annotation-example/src/main/java
- /custom-spring-@required-annotation-example/src/main/java/com
- /custom-spring-@required-annotation-example/src/main/java/com/memorynotfound
- /custom-spring-@required-annotation-example/src/main/java/com/memorynotfound/spring
- /custom-spring-@required-annotation-example/src/main/java/com/memorynotfound/spring/core
- /custom-spring-@required-annotation-example/src/main/java/com/memorynotfound/spring/core/required
/custom-spring-@required-annotation-example/src/main/java/com/memorynotfound/spring/core/required/Main.java
/custom-spring-@required-annotation-example/src/main/java/com/memorynotfound/spring/core/required/StarWars.java
/custom-spring-@required-annotation-example/src/main/java/com/memorynotfound/spring/core/required/TheForce.java
/custom-spring-@required-annotation-example/src/main/java/com/memorynotfound/spring/core/required/WeNeedThis.java
- /custom-spring-@required-annotation-example/src/main/java/com/memorynotfound/spring/core/required
- /custom-spring-@required-annotation-example/src/main/java/com/memorynotfound/spring/core
- /custom-spring-@required-annotation-example/src/main/java/com/memorynotfound/spring
- /custom-spring-@required-annotation-example/src/main/java/com/memorynotfound
- /custom-spring-@required-annotation-example/src/main/java/com
- /custom-spring-@required-annotation-example/src/main/java
- /custom-spring-@required-annotation-example

- Spring两种常用的事务管理范例AspectJ和基于注解方式
- [工作必备]spring定时器简单的demo
- 证 Spring通过配置component-scan base-package实现自动扫码指定路径的类并初始化bean的简单示例
- 证 Spring生命周期接口InitializingBean和DisposableBean的实例演示
- Java Spring的三种注入方式
- 证 spring通过@Async注解实现异步执行Service方法并且通过Java Future对象得到执行结果
- 证 spring通过p-namespace的方式实现xml配置bean的属性实例
- 证 spring通过c-namespace的方式实现xml配置bean构造函数实例
- 证 Spring通过properties文件的配置实现bean初始化的简单示例
- 证 Spring生命周期默认初始化和销毁方法通过xml配置实现
- spring 各种demo实例
- Java Spring定时器Demo, 可自动跳过节假日


fuyouou LV5
2023年7月6日
szf123 LV12
2023年5月30日
HusKies001
2021年6月29日
暂无贡献等级
wz66666 LV9
2021年6月8日
xiao菜 LV2
2021年6月2日
sanjooo LV5
2021年5月25日
xb1406112453 LV5
2021年4月15日
菜鸟蛋 LV2
2021年3月3日
fkhfsuhfuhflkk LV7
2021年2月20日
555551 LV1
2021年2月7日