AspectJExpressionPointcut使用了错误的classLoader
我有一个Java EE应用程序,该应用程序由在Apache Felix容器中运行的多个OSGI捆绑包组成.这些捆绑包之一负责加载弹簧应用程序上下文. 我在应用程序中使用Spring AOP,并且在我的捆绑包中出现以下错误: java.lang.IllegalArgumentException: warning no match for this type name: com.somepackage.SomeClass [Xlint:invalidAbsoluteTypeName] at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:301) at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.j
2 2023-05-14
编程技术问答社区
在getConnection时,spring方面没有被启动
我正在尝试在Spring 3.2.3 中拦截GetConnection呼叫 @Component @Aspect @Order(value = 1) public class ConnectionAspect { //@AfterReturning(pointcut = "execution(java.sql.Connection javax.sql.DataSource.getConnection(..))", returning = "connection") @Around("execution(java.sql.Connection javax.sql.DataSource.getConnection(..))") public Connection prepare(ProceedingJoinPoint pjp) throws Throwable { return MyConnectionProxy.newInstance((Con
46 2023-01-17
编程技术问答社区
如何在spring aspect中访问自定义注解的值
我正在尝试从TenchCut访问自定义注释值.但我找不到办法. 我的示例代码: @ComponentValidation(input1="input1", typeOfRule="validation", logger=Log.EXCEPTION) public boolean validator(Map mapStr) { //blah blah } 尝试访问@Aspect类. 但,我没有看到访问值的任何范围. 我试图访问的方式低于代码 CodeSignature codeSignature = (CodeSignature) joinPoint.getSignature(); String[] names = codeSignature.getParameterNames(); MethodSignature methodSignature = (MethodSignature) joinPoint.getSt
14 2023-01-17
编程技术问答社区
Spring AOP : 带有参数注解的接口方法被捕获,但注解并不存在
我正在使用spring aop拦截方法执行. 我有一个看起来如下所示的接口: public interface MyAwesomeService { public Response doThings(int id, @AwesomeAnnotation SomeClass instance); } 这是界面的实现: public class MyAwesomeServiceImpl implements MyAwesomeService { public Response doThings(int id, SomeClass instance) { // do something. } } 现在,我想要使用@awesomeannotation注释的参数的任何方法都应该被Spring Aop捕获. 所以我写了以下方面,工作. @Aspect @Component public class MyAwesomeAspec
10 2023-01-17
编程技术问答社区
将自定义注解建议应用到spring data jpa库中
我正在研究一个mysql主从的复制.我正在使用春天数据JPA(Spring Boot). 我所需要的是所有写入操作都要转到主服务器,只读操作,以在多个只读从站之间同样分布. 我需要: 使用特殊的JDBC驱动程序:com.mysql.jdbc.replicationdriver 设置复制:在URL中: spring: datasource: driverClassName: com.mysql.jdbc.ReplicationDriver url: jdbc:mysql:replication://127.0.0.1:3306,127.0.0.1:3307/MyForum?user=root&password=password&autoReconnect=true test-on-borrow: true validation-query: SELECT 1 database: M
26 2023-01-17
编程技术问答社区
Spring AOP:如何排除一个不必要的@Pointcut(@Around建议)的执行,因为其他@Pointcuts/建议的执行。
我正在使用: Spring Framework 4.3.3 AspectJ 1.8.9 我有以下正常过程: @Controller - > @Service - > @Repository 我有一个关于AOP: 的对 PersonaServicePointcut PersonaServiceAspect 方案如下: @Service类具有一些方法,例如:delete,save,update和findOneById.它们在同一类中声明在一起. 对于诸如delete和update的方法,我使用@Before或@Around建议来调用findOneById方法. 原因是没有意义执行 delete或update方法(如果实体不存在,则认为休息方案).因此,通过该advice一个例外必须抛出,让我们说异常 a ,它必须在@ControllerAdvice 中处理 已经应用了save方法的相同方法.因此,在执行中,save方法其他 @Befor
10 2023-01-17
编程技术问答社区
依赖性注入到Spring非管理型Bean中
我有一个不管理的JPA域类.它是通过new运算符实例化的. UserAccount account = new UserAccount(); userRepository.save(account) 在我的UserAccount类中,我有一个beforeSave()方法,该方法取决于我的SecurityService来编码密码. 我的问题是"如何让Spring DI注入安全服务?".似乎我需要的是InfackJ和LoadTime编织.我已经尝试了一个用于配置的数组,但是我似乎无法让其中任何一个工作.试图在注射对象上调用方法时,我总是会得到NullPointerException. useraccount.java (这是JPA实体) @Entity @Repository @Configurable(autowire = Autowire.BY_TYPE) public class UserAccount implements Serializable {
28 2023-01-17
编程技术问答社区
IntelliJ IDEA在方面定义的方法上 "无法解决方法"。
我正在使用 spring-data-neo4j 3.4.2 ,它(可选)使用axpectj. 我的IDE是Intellij Idea 16(EAP,IU-144.3891.8).我使用最新的Intellij Idea 15. 遇到了相同的问题. 到目前为止,一切正常在Intellij中正常工作,我可以编译,运行我的单元测试,部署并运行我的Web应用程序到/在Wildfly上等等. 在Intellij构建项目时,我可以看到所需方面的用法(以下警告是可以的). org.springframework.data.neo4j.aspects.support.node.Neo4jNodeBacking has not been applied [Xlint:adviceDidNotMatch] ... 我的问题:Intellij Idea正确使用弹簧射击/AJC.但是在编辑器中,这些方面未解决/使用.代码完成等不起作用. 在fackj-facet配置上,配置ap
8 2023-01-17
编程技术问答社区
使用Native AspectJ与Spring的问题
我正在测试specialj编译时春天4的时间编织(一旦我完成工作,我想在我的项目中使用它).我有以下服务类: @Service public class HelloService { public String sayHello(){ return sayHello2(); } public String sayHello2(){ return "Hello from AOP2!"; } } ,这是我的adview建议: @Component @Aspect public class ExecutionTimeAdvice { @Around("execution(* com.senyume.aop.service..*(..))") public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwab
16 2023-01-17
编程技术问答社区
春季应用中的非春季豆类的加载时间编织
我有一个Spring启动应用程序,具有一些REST控制器,服务类和辅助类.控制器和服务类是Spring管理的,而辅助类不是Spring的管理,并且主要包含静态方法. AspectJ配置以Java配置存在,如下所示 @Configuration @EnableLoadTimeWeaving(aspectjWeaving = AspectJWeaving.ENABLED) public class AspectConfig { @Bean public LoggingAspect loggingAspect() { return new LoggingAspect(); } } 相应的loggingAppate类如下所示, @Aspect public class LoggingAspect { @Before("allMethodsPointcut()") public void logBeforeMetho
12 2023-01-17
编程技术问答社区
如何使用Spring AOP或AspectJ拦截给定方法中的每个方法调用?
class Test { @override public String a(){ b(); d(); } private String b() { c(); } private String c(){ d(); } private String d(){} } 我想拦截来自覆盖方法a()的每种类测试方法,并且想知道单独处理某些业务逻辑的B(),c()所花费的每种方法的每种方法. 如何使用Spring Aop或AspectJ来实现它? 解决方案 以 编织成私人方法, 处理一个类内的自我调用, 动态地确定控制流程并仅通过界面方法直接或间接地调用的方法限制拦截 需要从Spring AOP(基于代理,许多限制,慢速)切换到 AspectJ使用LTW(负载时间编织)如Spring手册所述. 这是纯粹的Aspectj(没有Spring,Just Java SE)中的一个例子,您可以轻松适应您的需求: 样本接口 package de.s
26 2023-01-17
编程技术问答社区
如何将自定义的DaoAuthentication Provider加载到春季上下文中?
我有一个春季安全的问题. 我有一个带有SecurityConfig类的Java-Config实现,该类别扩展了WebSEcurityConfigurerAdapter. 在此类中,我想覆盖方法" configure()" @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, proxyTargetClass = true) public class SecurityConfig extends WebSecurityConfigurerAdapter{ @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { MyDaoAuthenticationProvid
4 2022-12-26
编程技术问答社区
春季自动连接的AOP循环依赖性
我正在使用@ComponentScan的java config才能初始化我的beans 和@EnableAspectJAutoProxy(proxyTargetClass=true)使用cglib代理. 在这个项目中,我们使用@Autowired在它们之间拥有很多生成的服务.它很好地工作. 但是,对于我添加的一些服务,我添加了@Async(我还在我的@Configuration类上添加@EnableAsync(proxyTargetClass = true)). 之后,我得到了: Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'ConversationUserLocalService': Bean with name 'ConversationUserLocalService' has been
26 2022-12-20
编程技术问答社区
从ProceedingJoinPoint检索参数值
在我的请求中,我有一个参数名称"AccessToken",如何从汇编joinpoint获取请求参数值? public Object handleAccessToken(ProceedingJoinPoint joinPoint) throws Throwable { final Signature signature = joinPoint.getStaticPart().getSignature(); if (signature instanceof MethodSignature) { final MethodSignature ms = (MethodSignature) signature; String[] params = ms.getParameterNames(); for (String param : params) { System.out.println(param);
8 2022-12-20
编程技术问答社区
Spring MVC和AOP。@Pointcuts只适用于Rest控制器,不适用于普通的Web控制器。
我正在 Web 环境中使用 Spring Framework 4.3.3. 我有一个 @Controller 通过 Web Browser 用于 Web 请求,该 Web Browser 使用其他 @Controller 的依赖关系,但用于 Rest 目的.后者提到使用 @Service 等... 这种关于使用“Rest"的“Web"的方法如何在 Combining Data and Presentation Formats 部分使用 Spring MVC 进行内容协商.直到这里进行开发/测试和生产工作正常.这是一种有价值的方法. 注意 Rest 类使用 @Controller 注释,因为我使用 ResponseEntity 和 @ResponseBody. 问题在于 AOP 关于我拥有的基础设施: @Configuration @EnableAspectJAutoProxy public class AopConfig { } 关于 @Con
106 2022-08-19
编程技术问答社区
获取Java中的所有异常并远程发送
我有一个巨大的 Java 应用程序.我想拦截所有 Java 异常并通过电子邮件发送它们.我无法在任何地方添加代码以通过 try-catch 发送代码,因此是否可以使用例如 Aspect 将异常拦截到低级类并获取异常内容? 或者有什么方法可以覆盖一些内部 Java 类并获取异常负载? 什么是可能的? 解决方案 可以使用spring-aop. @Aspect @Component public class MailExceptionAspect { @AfterThrowing(value="execution(* com.example..*.*(..))", throwing="ex" ) public void mailAfterThrowing(Throwable ex) { // do something to send an email } } 这将拦截 com.example 包中所有未处理的异常.请注意,在应
124 2022-08-13
编程技术问答社区
Java AOP连接点不获取参数名称
我正在使用 Java Spring Mvc 和 Spring AOP 从用户那里查找参数名称. 我有一个控制器,它从用户那里获取参数并调用服务. 我有一个在服务之前运行的方面. 方面应检查用户名和 apiKey 参数是否存在. 这是我的代码: 控制器: @RequestMapping(method = RequestMethod.POST, produces=MediaType.APPLICATION_JSON_VALUE) public @ResponseBody String getDomainWithFoundIn(@RequestParam (value="domain") String domain, @RequestParam (value="user") String user, @RequestParam (value="apiKey") String apiKey) throws JsonGenerationException, JsonMappin
4088 2022-07-17
编程技术问答社区