Tag: 方面

aspectj:如何将库中的方面编织成用户代码?

我有一个包含一些类和几个方面的库。 Say AspectedLib.jar是包含此类定义的文件(在eclipse中创建,带有“带有aspectj支持的导出jar文件”)。 如果我导入AspectedLib.jar文件,甚至使用其中定义的某些类,它可以工作,但没有触发任何连接点,即不执行方面。 我怎样才能做到这一点? 理想情况下,我如何在eclipse *中设置它? *版本:Juno Service Release 2; 构建ID:20130225-0426

如何使用AspectJ拦截处理自身exception的方法

我正在尝试在发生某些特定exception时添加一些监控。 例如,如果我有这样的方面: @Aspect public class LogAspect { @AfterThrowing(value = “execution(* *(..))”, throwing = “e”) public void log(JoinPoint joinPoint, Throwable e){ System.out.println(“Some logging stuff”); } } 和测试类: public class Example { public void divideByZeroWithCatch(){ try{ int a = 5/0; } catch (ArithmeticException e){ System.out.println(“Can not divide by zero”); } } public void divideByZeroWithNoCatch(){ int b = […]

在Eclipse中为Roo项目自动完成

我有一个Roo项目,我已经制作了几个实体,当我在Eclipse中加载项目时,它加载得很好,但是如果我做一个实例MyEntity entity然后写entity. 我没有在自动完成列表中获得任何属性(即getMyField)。 如果我编写entity.getMyField()它编译正常,由方面处理。 如何为方面生成的函数启用自动完成function? 干杯 聂

@Around @Aspect在同一个包中仅适用于@DependsOn

请参阅以下更新。 我有一个Spring Boot应用程序,我接受TCP / IP连接: public MyClass implements InitializingBean { @Override public void afterPropertiesSet() throws Exception { try (ServerSocket serverSocket = new ServerSocket(port)) { while (true) { Socket socket = serverSocket.accept(); new ServerThread(socket).start(); } } } … private class ServerThread extends Thread { @Override public void run() { try (InputStream input = socket.getInputStream(); OutputStream output […]

Spring Boot Logger方面

当访问特定包的类中的方法时,我在记录日志信息时遇到问题。 换句话说,发生“不”记录。 我甚至绝望并添加了System.out.println语句,没有运气。 我的所有类都位于org.my.package包下,即org.my.package.controller , org.my.package.model等。 这是我的Application类: package org.my.package; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; @Configuration @ComponentScan(basePackages = {“org.my.package.config”}) @EnableAutoConfiguration @EnableAspectJAutoProxy public class FirstWebAppApplication { public static void main(String[] args) { SpringApplication.run(FirstWebAppApplication.class, args); } } 这是我的配置类: package org.my.package.config; import org.deloitte.javatraining.daythree.utilities.MyLogger; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; @Configuration @EnableAspectJAutoProxy @ComponentScan(basePackages […]

@ afterpectJ语句为“after():staticinitialization(*)”

我正在尝试使用实例化模型中的pertype实现跟踪方面。 通过这种方式,我将能够为每种类型的每个类使用一个记录器。 从我们的一些例子中我可以找到这个代码来初始化记录器: public abstract aspect TraceAspect pertypewithin(com.something.*) { abstract pointcut traced(); after() : staticinitialization(*) { logger = Logger.getLogger(getWithinTypeName()); } before() : traced() { logger.log(…); } //…. } 不幸的是,我无法将其完全转换为@AspectJ语法(这是我控制之外的项目要求),尤其是我需要设置记录器的部分,只执行一次该代码。 这可能吗? 谢谢,

AspectJ可以穿过sun.net。*包吗?

我正在使用AspectJ来拦截java.net.Socket调用。 我创造了非常简单的方面 after(): call(* java.net.Socket.connect(..)) { System.out.println(“Connect intercepted!”); } 和aop.xml 当调用堆栈是这样的,那么我可以看到控制台输出: java.lang.Exception at com.iggroup.lightstreamer.nwtp.SocketExceptionLoggingAspect.ajc$after$com_iggroup_lightstreamer_nwtp_SocketExceptionLoggingAspect$2$6e16217c(SocketExceptionLoggingAspect.aj:39) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:337) at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353) at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55) at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:91) at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:596) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557) at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:475) at com.iggroup.lightstreamer.nwtp.users.SsoRestClientImpl.lambda$0(SsoRestClientImpl.java:68) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at […]