
Spring
文章平均质量分 62
Spring
普通人zzz~
除了成功,别无选择
展开
-
Spring 发布订阅
这里写目录标题Spring 发布订阅示例1. 定义事件2. 定义事件监听者2.1 普通类写法2.2 实现ApplicationListener接口写法3. 发布事件Spring 发布订阅Spring 中的事件机制涉及到者几个类文件 :ApplicationEvent(事件类型)、ApplicationListener(事件监听类)、ApplicationEventPublisher(事件发布类)。ApplicationEvent:继承JDK java.util.EventObject。publi原创 2021-05-23 21:49:59 · 293 阅读 · 0 评论 -
Spring 扩展接口
Spring 扩展接口1. BeanPostProcessor2. BeanFactoryPostProcessor3. InitialingBean和DisposableBean4. FactoryBean5. BeanDefinitionRegistryPostProcessor6. BeanNameAware、ApplicationContextAware 和 BeanFactoryAware7. 后续再进行添加补充1. BeanPostProcessorBeanPostProcessor 接口是原创 2021-05-23 15:17:33 · 2932 阅读 · 1 评论 -
Spring 框架——利用HandlerExceptionResolver实现全局异常捕获
HandlerExceptionResolver一、需求描述二、基本应用一、需求描述因为在项目中,我们不可否认的会出现异常,而且这些异常并没有进行捕获。经常出现的bug如空指针异常等等。在之前的项目中,如果我们没有进行任何配置,那么容器会自动打印错误的信息,如果tomcat的404页面,400页面等等。如果我们在web.xml中进行如下配置,就会拦截错误,然后跳转到指定的错误页面。<error-page> <error-code>500</error-code&g原创 2021-04-17 17:19:41 · 323 阅读 · 0 评论 -
Spring 中 EmbeddedValueResolverAware
Spring 获取 properties 文件单个属性值,一般使用 @Value 件属性值。下面提供另一种基于Spring解析获取 properties 文件单个属性值的方式,使用 EmbeddedValueResolverAware 。properties 文件:db.user=rootdb.password=123456db.driverClass=com.mysql.jdbc.DriverPropertiesUtil 工具类:@Component//@PropertySource("转载 2021-04-17 17:13:59 · 267 阅读 · 0 评论 -
Spring-scope详解
Spring中的scope配置xml方式注解方式scope类型singleton(单一实例)此取值时表明容器中创建时只存在一个实例,所有引用此 bean 都是单一实例。此外,singleton 类型的 bean 定义从容器启动到第一次被请求而实例化开始,只要容器不销毁或退出,该类型的 bean 的单一实例就会一直存活,典型单例模式,如同 servlet 在 web 容器中的生命周期。prototypeSpring 容器在进行输出 prototype 的 bean 对象时,会每次都重新生原创 2021-01-19 18:16:03 · 300 阅读 · 0 评论 -
Spring 中 @ConditionalOnXXXX系列注解
@ConditionalOnXXXX系列注解1. @ConditionalOnBean概念2. @ConditionalOnBean定义3. @ConditionalOnBean示例3.1 创建一个Bean13.2 创建一个bean23.3 注入4. @ConditionalOnXXXX系列常用注解@Conditional 注解后,Spring4 又基于此注解推出了很多派生注解,如@ConditionalOnBean、@ConditionalOnMissingBean、@ConditionalOnExpr原创 2020-06-12 10:55:08 · 1463 阅读 · 0 评论 -
Spring 中 @Conditional注解
@Conditional 是 Spring4 新提供的注解,它的作用是按照给定条件判断是否注册bean。@Conditional的定义:@Target({ElementType.TYPE, ElementType.METHOD})@Retention(RetentionPolicy.RUNTIME)@Documentedpublic @interface Conditional { Class<? extends Condition>[] value();}由定义可以得出:原创 2020-06-11 15:29:27 · 204 阅读 · 0 评论 -
Spring 之 InitializingBean接口
Spring的 InitializingBean 接口为 bean 提供了初始化执行方法的方式,该接口只包括 afterPropertiesSet() 方法。凡是继承该接口的类,在初始化 bean 的时候都会执行该方法。package org.springframework.beans.factory;public interface InitializingBean { void afterPropertiesSet() throws Exception;}Spring在配置bean的原创 2020-05-13 11:18:24 · 196 阅读 · 0 评论 -
Spring 统一参数校验(Validator + BindingResult)
这里写目录标题简介示例代码常用校验注解使用AOP(@Aspect)或@ControllerAdvice进一步封装@ControllerAdvice封装AOP(@Aspect)封装简介Java项目传参时,可能有许多字段都需要进行校验,可以通过javax.validation.constraints.*包下的注解,再配合 @Valid 和 BindingResult 进行错误信息的返回。示例代...原创 2020-04-21 15:50:16 · 3970 阅读 · 0 评论 -
@PostConstruct和@PreDestroy注解
这里写目录标题@PostConstruct@PreDestroyJava EE5引入了@PostConstruct和@ProDestory两个作用于Servlet生命周期的注解,实现Bean初始化之前和销毁之前的自定义操作。@PostConstruct应用 PostConstruct 注释的方法必须遵守以下所有标准:只有一个方法可以使用此注释进行注解;被注解方法需是非静态方法;被注解...原创 2020-04-01 10:09:31 · 421 阅读 · 0 评论 -
Spring AOP配置 之 @Aspect
@Aspect一、AOP概念(百度)二、AOP基本术语三、Advice类型四、Sping @Aspect开发步骤五、执行顺序六、试例代码一、AOP概念(百度) AOP(Aspect Oriented Programming):面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术。AOP是OOP的延续,是软件开发中的一个热点,...原创 2020-04-13 17:03:38 · 6141 阅读 · 2 评论 -
Spring AOP配置 之 @PointCut语法
@PointCut语法切点表达式1. execution2. within3. this和target4. args(paramType)5. @within(annotationType)6. @target(annotationType)7. @annotation(annotationType)8. @args(annotationType)@Pointcut可以是由切点表达式来定义或者通...原创 2020-04-13 16:58:53 · 1314 阅读 · 0 评论