sat*_*sat 5 spring aspectj spring-aop load-time-weaving spring-boot
不知道出了什么问题,但AOP似乎没有在弹簧启动(v1.1.6)的设置中工作.
@Configuration
@ComponentScan
@EnableJpaRepositories
@EnableTransactionManagement
@EnableAutoConfiguration
@EnableCaching
@EnableLoadTimeWeaving
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
而在方面类
@Aspect
public class MyAspect {
@AfterReturning(pointcut = "execution(private * com.myapp.service.MyService.test(..)) && args(str1,str2)", argNames = "str1,str2")
public void advice(String str1, String str2) throws IOException {
System.out.println("Advising after returning");
}
}
Run Code Online (Sandbox Code Playgroud)
在需要建议的服务类中
@Service
public class MyService {
public void test(String str1, String str2) throws IOException {
System.out.println("Test method in service");
//rest of the implementation
}
}
Run Code Online (Sandbox Code Playgroud)
我也有像这样的META-INF/aop.xml
<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>
<weaver>
<!-- only weave classes in our application-specific packages -->
<include within="com.myapp.*"/>
</weaver>
<aspects>
<!-- weave in just this aspect -->
<aspect name="com.myapp.aspect.MyAspect"/>
</aspects>
</aspectj>
Run Code Online (Sandbox Code Playgroud)
当我使用-javaagent运行应用程序时:path/to/spring-instrument-4.1.0.RELEASE.jar
我在控制台上收到此消息
2014-09-05 08:42:12.500 INFO 65053 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
[AppClassLoader@58644d46] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified
2014-09-05 08:42:13.114 INFO 65053 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2014-09-05 08:42:13.156 INFO 65053 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Registering beans for JMX exposure on startup
[AppClassLoader@58644d46] error can't determine implemented interfaces of missing type org.springframework.security.config.http.SessionCreationPolicy
when weaving type org.springframework.boot.actuate.autoconfigure.ManagementServerProperties$Security
when weaving classes
when weaving
[Xlint:cantFindType]
[AppClassLoader@58644d46] error can't determine implemented interfaces of missing type org.springframework.security.config.http.SessionCreationPolicy
when weaving type org.springframework.boot.actuate.autoconfigure.ManagementServerProperties$Security
when weaving classes
when weaving
[Xlint:cantFindType]
Run Code Online (Sandbox Code Playgroud)
但是这个建议没有任何结果.它不会开火.
难道我做错了什么?
为了建议私有方法,您需要使用特权方面:
public privileged aspect MyAspect {
// ...
}
Run Code Online (Sandbox Code Playgroud)
但AspectJ 文档说:
限制:注释样式不支持特权方面。
所以请使用原生语法,而不是@AspectJ 风格。不过,在执行此操作之前,请测试非特权注释样式方面是否按公共方法的预期工作,以排除编织方面的其他原因。
归档时间: |
|
查看次数: |
4461 次 |
最近记录: |