spring-aop

injecting mock beans into spring context for testing

三世轮回 提交于 2019-11-30 04:00:54
I know similar questions have been asked, e.g. here , but having done a search, I've come upon a solution I'm much happier with here My only problem however, is that I'm not sure how to implement this solution. What I want to be able to do is via the HotswappableTargetSource override the bean definitions of select beans in my application context with my test versions and then run the test. Then for each test case I'd like to specify which beans I want to be hot swappable and then each test must be able to create its own mock versions and swap those in, and be able to swap back again. I am able

Spring application has Cglib2AopProxy warnings

半腔热情 提交于 2019-11-30 03:55:18
Upon starting my application, I get numerous warnings along the lines of o.s.aop.framework.Cglib2AopProxy 'Unable to proxy method [public final void org.springframework.jdbc.core.support.JdbcDaoSupport.setDataSource(javax.sql.DataSource)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.' for about a dozen or so functions. Now I perfectly understand that proxy-based aspects cannot be applied to final methods. However, I did not (on purpose, at least) try to weave any aspects into JdbcDaoSupport . I suspect it comes from <tx:annotation-driven /> .

Enable Spring AOP or AspectJ

若如初见. 提交于 2019-11-30 02:21:22
This is following on from this question: Spring autowired bean for @Aspect aspect is null My initial understanding was that when using Spring AOP, classes annotated with @Aspect are created as spring managed beans, so dependency injection would work as normal. However it seems that an object with the @Aspect annotation is created as a singleton outside the spring container, hence me having to configure it in XML like so in order to enable it as a spring managed bean: <bean id="aspect" class="com.mysite.aspect" factory-method="aspectOf" /> This has now completely confused me. I thought the

Basic AOP program throws BeanCurrentlyInCreationException

大兔子大兔子 提交于 2019-11-29 14:46:31
I am creating a simple AOP program and starting getting BeanCurrentlyInCreationException exception with it. Here is my code: MyAspect.java package aspect; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import org.springframework.stereotype.Component; @Aspect //@Component public class MyAspect { @Pointcut("execution(public * *(..))") private void anyPublicOperation() { } @Before("anyPublicOperation()") private void beforePointCut(){ System.out.println("Inside before pointcut of MyAspect"); } } Calculator.java

Spring AOP CGLIB proxy's field is null

陌路散爱 提交于 2019-11-29 13:59:11
Description Using the vlcj component, the custom component appears as a result of the AOP proxy object null. MediaList Class public class MediaList { private libvlc_media_list_t mediaListInstance; public MediaList(LibVlc libvlc, libvlc_instance_t instance, libvlc_media_list_t mediaListInstance) { this.libvlc = libvlc; this.instance = instance; createInstance(mediaListInstance); } private void createInstance(libvlc_media_list_t mediaListInstance) { logger.debug("createInstance()"); if(mediaListInstance == null) { mediaListInstance = libvlc.libvlc_media_list_new(instance); } else { libvlc.libvlc

JUnit tests for AspectJ

∥☆過路亽.° 提交于 2019-11-29 11:28:07
问题 I am trying to write Junit tests for Custom Aspect. Here is the Aspect Class Snippet: @Aspect @Component public class SampleAspect { private static Logger log = LoggerFactory.getLogger(SampleAspect.class); @Around("execution(* org.springframework.data.mongodb.core.MongoOperations.*(..)) || execution(* org.springframework.web.client.RestOperations.*(..))") public Object intercept(final ProceedingJoinPoint point) throws Throwable { logger.info("invoked Cutom aspect"); return point.proceed(); }

Can we enable or disable Aspect based on value of any flag or through configuration file?

痞子三分冷 提交于 2019-11-29 07:36:32
I have added following dependency in pom.xml <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.8.5</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.8.5</version> </dependency> And enable AspectJ in appContext.xml as follows: And define aspect as follows: @Component @Aspect public class AuthenticationServiceAspect { @Before("execution(* com.service

Why Spring AOP is not weaving external jars at runtime?

孤者浪人 提交于 2019-11-29 04:47:58
问题 I have a java application build upon Spring 3. This project has another jar as a dependency. This dependency contains a @org.aspectj.lang.annotation.Aspect class (lets say, com.aspectprovider.aspects.MyAspect ). There's a @Before advice to weave a method from classes that implements the interface Foo . Something like: @Before("execution(* com.project.Foo.save(..))") The Foo interface can be inside the "project" or in another jar. It doesn't matter for this example. My project contains classes

Spring AOP at Service Layer

佐手、 提交于 2019-11-29 04:16:45
问题 I need some help with Spring AOP. I've the following code: @Service public class UserSecurityService implements UserDetailsService { @Autowired private UserService userService; .... } @Service public class UserService extends CrudService<User, UserRepository> { public UserService() { super(); } @Autowired public UserService(UserRepository repository) { super(repository); this.repository = repository; } .... } @Repository interface UserRepository extends JpaRepository<User, String> { ... }

Spring AOP: Getting parameters of the pointcut annotation

人走茶凉 提交于 2019-11-29 03:41:25
Consider I have defined the following aspect: @Aspect public class SampleAspect { @Around(value="@annotation(sample.SampleAnnotation)") public Object display(ProceedingJoinPoint joinPoint) throws Throwable { // ... } } and the annotation public @interface SampleAnnotation { String value() default "defaultValue"; } Is there a way to read the value parameter of the annotation SampleAnnotation in the display method if my aspect? Thanks for your help, erik David Rabinowitz Change the advice signature to @Around(value="@annotation(sampleAnnotation)") public Object display(ProceedingJoinPoint