java学习简单笔记20190225

spring boot Aop,可自定义切点

public @interface Action{

   string name();

},在方法的前面标注

@Action(name=“xxxxxxx")

public void add()

可通过切面类传入的JoinPoint切点参数,joinPoing.getSignatur().getMethod().getAnnotation(Action.class).name反射方法获取注明的文字。

Bean的Scope生成方式@Scope("xxxxx"),默认不加注解是生成静态对象,共享同一个实例的

Prototype,每次生成都新建一个bean实例;

Request:在web项目中,每一个request请求就新建一个Bean实例;

Session:每 一个session新建一个bean实例;

GlobalSession:在portal应用中,每 一个session新建一个实例

例如

@Scope("Prototype")

public class testccc(),生多个不同的Bean实例。

Spring EL表达式@Value,可在spring的注解中使用表达式可实现普通字符、操作系统系统、表达式计算结果、其他bean的属性、文件内容、网址内容、属性文件的使用。

若要使用属性文件,需在类上面注解文件路径,@PropertySource("classpath:xxxxxxx/xx.properties")

Bean的初始化和销毁,使用@Bean的(init-Method和destory-Method)来指定要生成的类在初始化后和销毁前执行生成类中本身中的方法@Bean(initMethod="aa",destroyMethod=”bb")

 @Profile注解选择运行环境,在@bean的注解后,再在要生成的类注解@Profile(”dev"),在配置context.getEnvironment().setActiveProfiles("dev")后,当context.getBean(xxx.class)时,就会根据@Profile(“dev")生成不同的bean实例了

Application Event事件,步骤1、自定义事件,集成ApplicationEvent,;2、定义事件监听器ApplicationListener;3、使用容器发布事件

1、自定义事件:public class myevent extends ApplicationEvent{......}

2、定义事件监听器:public class implements ApplicationListener<myevent>{............}

3、使用容器发布事件:public class mypublisher { void dopublis() { applicationContext.publishEvent(new myevent(xxxxx,xxxx)); } }

配置类上在一般都有的注解@Configuration、@ComponentScan("com.xxxx.xxxxx")

原文地址:https://www.cnblogs.com/lofe/p/10435123.html