漠北空城

听海观潮


  • 首页

  • 关于

  • 标签

  • 归档

  • 搜索

IDEA JAVA模板定义

发表于 2020-03-25

IDEA JAVA模板定义

1、Settings->File and Code Templates

Includes标签下
点击加号,添加文件,重命名为:File Header
添加内容为:

1
2
3
4
5
6
7
8
/**
*
* ${DESCRIPTION}
*
* @author ${USER}
* @version 1.0
* @date ${YEAR}-${MONTH}-${DAY} ${TIME}
*/

2、Settings->File and Code Templates

Files标签下
Class修改为:

1
2
3
4
5
/* Copyright © 2020 Yuech and/or its affiliates. All rights reserved. */
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
public class ${NAME} {
}

Interface修改为:

1
2
3
4
5
/* Copyright © 2020 Yuech and/or its affiliates. All rights reserved. */
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
public interface ${NAME} {
}

Enum修改为:

1
2
3
4
5
/* Copyright © 2020 Yuech and/or its affiliates. All rights reserved. */
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
public @interface ${NAME} {
}

AnnotationType修改为:

1
2
3
4
5
/* Copyright © 2020 Yuech and/or its affiliates. All rights reserved. */
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
public @interface ${NAME} {
}

3、新建java代码时,填写类注释到弹出的DESCRIPTION框中

Eclipse各个版本及其对应代号列表

发表于 2018-07-01

Eclipse各个版本及其对应代号列表

版本号 代码 日期
Eclipse 3.1 IO[木卫一,伊奥] 2005
Eclipse 3.2 Callisto[木卫四,卡里斯托] 2006
Eclipse 3.3 Eruopa[木卫二,欧罗巴] 2007
Eclipse 3.4 Ganymede[木卫三,盖尼米德] 2008
Eclipse 3.5 Galileo[伽利略] 2009
Eclipse 3.6 Helios[太阳神] 2010
Eclipse 3.7 Indigo[靛青] 2011
Eclipse 4.2 Juno[朱诺] 2012
Eclipse 4.3 Kepler[开普勒] 2013
Eclipse 4.4 Luna[月食] 2014
Eclipse 4.5 Mars[火星] 2015
Eclipse 4.6 Neon[霓虹灯] 2016
Eclipse 4.7 Oxygen[氧气] 2017
Eclipse 4.8 Phton[光子] 2018
阅读全文 »

ThreadLocal之两则应用场景

发表于 2018-06-19

ThreadLocal之两则应用场景

应用场景两则

  • 1、利用ThreadLocal管理登录用户信息实现随用随取
  • 2、可以记录Controller各个请求的执行时间

场景1spring boot实现步骤:

  • 1、新建实现WebMvcConfigurerAdapter的类,重写addInterceptors方法,registry添加实现了HandlerInterceptorAdapter类的拦截器,
    同时设置需要拦截与不需要拦截的路径正则表达式;
  • 2、在拦截器类中从session中取出用户信息,存入ThreadLocal中;
  • 3、引入spring-boot-starter-aop依赖,设置切入点(Pointcut)为controller中的各个方法,在AOP的后置最终通知(@After)中删除ThreadLocal中的信息
    注意:当然需要在登录时将登录用户信息存入session中
阅读全文 »

dubbo-admin-2.0.0管理控制台安装

发表于 2018-03-26

dubbo-admin-2.0.0管理控制台安装

dubbo-admin-2.0.0管理控制台安装

环境

  • Maven: Apache Maven 3.3.3
  • Server version: Apache Tomcat/9.0.6
  • OS Name: Linux
  • JVM Version: 1.8.0_161-b12
  • OS Version: 3.10.0-514.26.2.el7.x86_64
  • Dubbo admin: 2.0.0

1、在github上获得dubbo-admin源码

通过下面命令克隆dubbo-admin项目

1
git clone https://github.com/apache/incubator-dubbo-ops.git

阅读全文 »

Spring-AOP-配置

发表于 2017-11-28

Spring-AOP-配置

spring-AOP-配置

1、步骤

1.1、创建一个接口PersonDao
1.2、创建一个目标类PersonDaoImpl
1.3、创建一个事务Transaction
1.4、把目标类和事务放入到spring容器中
1.5、进行aop的配置
1.5.1、引入aop的命名空间
1
2
3
xmlns:aop="http://www.springframework.org/schema/aop"
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
1.5.2、把PersonDao和Transaction放入到spring容器中
1
2
<bean id="personDao" class="..."></bean>
<bean id="transaction" class="..."></bean>
1.5.3、进行aop的配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<aop:config>
<!--
切入点表达式
id为该切面点表达式的唯一标示
-->
<aop:pointcut expression="execution(* com.yc.spring.PersonDaoImpl.*(..))"
id="perform"/>
<!--
一个aspect代表一个切面
-->
<aop:aspect ref="transaction">
<!--
前置通知:
1、在目标方法执行之前执行;
2、在前置通知中有一个参数:JoinPoint,该参数可以获取目标方法的一些信息;
-->
<aop:before method="beginTransaction" pointcut-ref="perform"/>
<!--
后置通知
1、在目标方法执行之后;
2、如果目标方法遇到异常,则后置通知将不在执行;
3、方法中也有两个参数:
JoinPoint:
Object:该参数的名称要与returing配置的参数名称一致
4、能够获取目标方法的返回值;
-->
<aop:after-returning method="commit" pointcut-ref="perform" returning="obj"/>
<!--
最终通知
无论目标方法是否遇到异常,都会执行
-->
<aop:after method="finallyMethod" pointcut-ref="perform"/>
<!--
异常通知
1、获取目标方法获取的异常信息
2、throwing="ex",异常通知中的异常的名称必须是ex
-->
<aop:after-throwing method="throwingMethod" pointcut-ref="perform" throwing="ex"/>
<!--
环绕通知
1、控制目标方法的执行;
2、该方法中有一个ProceedingJoinPoint参数;
3、该参数的proceed()方法调用的是目标方法,,如果该方法不调用,则目标方法不会执行;
4、可以从ProceedingJoinPoint中得到目标方法的一些信息;
5、需要返回时,环绕通知方法也需要返回
6、环绕通知和前置通知/后置通知一般不同时存在
7、前置通知和后置通知不能控制目标方法的执行;
-->
<aop:around method="aroundMethod" pointcut-ref="perform"/>
</aop:aspect>
</aop:config>

2、原理:

  • 1、启动spring容器,把personDao和transaction实例化
  • 2、当spring容器解析到aop:config配置的时候,会解析切入点表达式
  • 3、把切入点表达式解析出来以后,和spring容器中的bean做匹配,如果匹配成功,则为该bean创建代理对象;
  • 4、代理对象的方法的创建过程就把通知和目标方法结合在一起了
  • 5、当在客户端执行context.getBean时,先检查跟bean是否有代理对象,如果有代理对象,则返回代理对象;如果没有代理对象,则返回对象本身
    注意:如果切入点表达式在spring容器中没有找到匹配的对象,则会报错

3、切入点配置说明

下面是spring切入点的配置说明:

1
execution(modifiers-pattern? ret-type-pattern declaring-type-pattern?name-pattern(param-pattern)throws-pattern?)

直接看的话,还是不是很好理解
通过一个方法声明的来对比说明一下:

1
public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException

修饰符类型 返回值类型 声明类型 方法名 参数类型 异常类型
modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern param-pattern throws-pattern?
public void java.lang.Object wait long throws java.lang.InterruptedException

切入点配置举例:
execution (public (..) ) : 表示任意公共方法
execution ( set(..) ) : 表示以set开头的任意方法
execution ( com.xyz.service.AccountService.(..) ) : 表示com.xyz.service.AccountService类中的所有方法
execution ( com.xyz.service..(..) ) :表示com.xyz.service包下的所有的类的所有的方法
execution (
com.xyz.service...(..) ) :表示com.xyz.service包下及其子包下的所有的类的所有的方法

123…14
漠北空城

漠北空城

69 日志
19 标签
链接
  • xyz327
© 2024 漠北空城
由 Hexo 强力驱动
|
主题 — NexT.Gemini v5.1.4
粤ICP备18054530号-2   |     |