Spring中的初始化注解@PostConstruct
来源:互联网 发布:睿至大数据孙亮 编辑:程序博客网 时间:2024/06/06 16:25
配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:lang="http://www.springframework.org/schema/lang" xmlns:oxm="http://www.springframework.org/schema/oxm"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.2.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<!-- spring的注解 -->
<!-- <context:annotation-config/> -->
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />
<bean id="person" class="aop.Person">
<property name="message" value="123"></property>
</bean>
<!-- 切点 -->
<bean id="log" class="aop.Log"/>
<!-- 切点通知,前置通知,后置通知,success通,环绕通知 .配置各种通知-->
<!-- <aop:config>
<aop:aspect ref="log">
声明切入点,方法名。第一个*返回的参数,第二个*任意的类名名,第三个参数*是任意的,括号里面的时任意的参数
<aop:pointcut expression="execution(* aop.*.*(..))" id="oprater"/>
配置切点
<aop:before method="before" pointcut-ref="oprater"/>
<aop:after-returning method="success" pointcut-ref="oprater"/>
<aop:after method="after" pointcut-ref="oprater"/>
<aop:around method="around" pointcut-ref="oprater"/>
</aop:aspect>
</aop:config> -->
<!-- 创建bean -->
<bean id="ope" class="aop.Operate"></bean>
<bean id="aop" class="aop.Aop"></bean>
</beans>
配置文件中的注册:
<context:annotation-config>与
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"/>作用是一样的
实体类中的
package aop;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
public class Person {
private String message;
public String getMessage(){
return message;
}
public void setMessage(String message){
this.message=message;
}
@PostConstruct
public void init(){
System.out.println("开始时先进行初始化"+message);
}
@PreDestroy
public void destroy(){
System.out.println("结束的时候销毁"+message);
}
}
- Spring中的初始化注解@PostConstruct
- PostConstruct 注解 配合 spring注解使用
- @PostConstruct和@PreConstruct注解实现Spring been的初始化和销毁
- spring使用注解@PostConstruct的xml配置
- Spring Annotation(注解) @Scope ,@PostConstruct 和@PreDestroy
- Spring注解之 @PostConstruct和 @PreDestroy
- Spring之@PostConstruct和@PreConstruct注解
- @PostConstruct注解
- @PostConstruct注解
- 注解@PostConstruct
- Spring PostConstruct
- SPRING-MVC注解@PostConstruct与@PreDestroy讲解及实例
- Spring 基于注解的配置(三)(@Resource,@PostConstruct ,@PreDestory)
- Spring浅析之注解之二:spring支持的JSR-250注解之:@PostConstruct、@PreDestroy
- 注解@PostConstruct与@PreDestroy
- 注解@PostConstruct与@PreDestroy
- 注解@PostConstruct与@PreDestroy
- 注解@PostConstruct与@PreDestroy
- 如何获取当前日期和时间
- HTMLParser使用
- http://codeforces.com/problemset/problem/716/C Plus and Square Root
- 基本实现京东购物车 mysql+php+html
- Most Frequent Subtree Sum
- Spring中的初始化注解@PostConstruct
- maven 项目搭建spring+springMVC+mybatis
- mysql安装
- 多线程卖票
- u盘装系统详细教程
- 手把手教你如何搭建一个自己的安卓快速开发框架之带你做自己的APP(三)
- mysql事务特性及隔离级别整理
- 第四次实验 函数调用
- PAT 乙级 外星人的语言 1017