spring-aop

Spring self injection for transactions

假装没事ソ 提交于 2019-12-08 15:46:41
问题 In Spring you can't simply call @Transactional method from the same instance, because of AOP-proxy thing. Would it be nice idea to make a self injection and call that method from self proxy instance? Do you see any drawbacks? 回答1: It is totally ok. Moreover there was a Jira ticket for supporting this feature using @Autowired annotations. It's fixed in Spring 4.3+ versions. However for xml-based configuration or using @Resource annotation it's working in the earlier versions. You can see the

Spring AOP Pointcut expression for annotated field

半世苍凉 提交于 2019-12-08 13:56:27
Is it possible to capture any field with a specific annotation? My end goal is to inject a value into that field, but currently my pointcut is wrong (not sure of the correct syntax). @Pointcut("execution(* *(..)) && @annotation(com.mycompany.MyAnnotation)") private void annotatedField(){} @Around("annotatedField()") public Object injectValue(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable {} I believe the pointcut is stating any Method with the annotation. and I want to change that to say any Field. I think you should follow the advice of Sotirios Delimanolis and get as far as

Spring Annotation based AOP to intercept method implemented in parent class

送分小仙女□ 提交于 2019-12-08 11:08:44
问题 We are using annotation based AOP for methods to intercept functionality. Base interface: public interface BaseInterface { public void someMethod(); } Abstract Base implementation: public abstract class AbstractBaseImplementation implements BaseInterface { public void someMethod() { //some logic } } Child interface: public interface ChildInterface extends BaseInterface { public void anotherMethod(); } Implementation Class public class ActualImplemetation extends AbstractBaseImplementation

How to order @Aspect

放肆的年华 提交于 2019-12-08 11:06:13
问题 In a (Spring boot) application using a lot of @Aspect How would you ensure the correct aspects ordering with @Order , knowing that you can't have a central place to define the ordering since these aspects may reside in different libs used by different applications? How would you list all the @Aspect present in the application context, an their order ? Does it make sense to use @DeclarePrecedence in a separate @Aspect to ensure the ordering instead of @Order for such a use case ? 回答1: I am not

spring using CGLIB proxy even when class implements interface

流过昼夜 提交于 2019-12-08 09:19:50
问题 I'm trying to use Spring AOP to intercept methods of my GWT-RPC application (using GWT-Server library, so RPC service doesn't extend RemoteServiceServlet). When I deploy my war to tomcat and start the application, CGLIB fails for some reason. But I don't understand why CGLIB is being used for proxying at the first place. Since my RPC class implements the interface, shouldn't it be using JDK dynamic proxies? Is there anything I need to do to debug this issue? Kindly advise. Note: FYI, Spring

Spring Data Rest Override Repositories (Controllers vs AOP)

。_饼干妹妹 提交于 2019-12-08 07:53:06
问题 Domain/Repository Project { User owner; } //Querydsl repositories @RepositoryRestResource public interface ProjectRepository extends PagingAndSortingRepository<Project, Long>, QueryDslPredicateExecutor<Project>, QuerydslBinderCustomizer<QProject> { default void customize(QuerydslBindings bindings, QProject project) { (...) } } Requeriment: filter data according to the authenticated user context: If user is ROLE_PUBLIC show projects according predicate and where user is the owner . If user is

Struts 2 action method intercepting using Spring AOP

孤人 提交于 2019-12-08 07:00:45
问题 I'm trying to intercept the Struts2 Action class's methods to print the method start and method end indication statement using Spring AOP. The fact is , my Struts2 actions instance are also Spring beans (Struts2 and Spring integration done as per the url: http://www.mkyong.com/struts2/struts-2-spring-integration-example/). AOP configurations is as below: <bean id="testAdviceBean" class="com.tcs.oss.plugins.SimpleAdvice"> </bean> <aop:config> <aop:aspect ref="testAdviceBean" order="200"> <aop

Spring-AOP load-time weaving on 3rd-party classes

落花浮王杯 提交于 2019-12-08 06:03:46
问题 I wrote an aspect that I'm trying to test with junit. The aspect has an @Around advice on a 3rd party method called setQuery . At compile time it complains: Can't find referenced pointcut setQuery Here's my aspect: @Component @Aspect public class ElasticsearchQuerySecurityAspect { @Around("org.elasticsearch.action.search.SearchRequestBuilder.setQuery() && args(queryBuilder)") public void addFilter(final ProceedingJoinPoint pjp, QueryBuilder queryBuilder) throws Throwable { Object[] args = pjp

GWT: get locale information from server side?

Deadly 提交于 2019-12-08 01:38:52
问题 I use GWT along with Spring/Hibernate/AOP. I use an Aspect to send notification emails. In one of my Aspect, I want to get the current locale from GWT,so that I can send the localized email to the user. Is there a way to access GWT Locale data from the client side? Thanks 回答1: http://code.google.com/intl/es-ES/webtoolkit/doc/latest/DevGuideI18nLocale.html has info about Locales in GWT. I have two approaches: 1) session-less server: the method in the server that sends the email receives the

AOP Using Around to avoid executing a method

拈花ヽ惹草 提交于 2019-12-08 00:31:14
问题 I am using Spring AOP in my code to intercept the execution of a certain method. A simplified example of what I'm trying to do is below: public void someMethod() { //does something } @Around("execution( someMethod())") public void anotherMethod(final ProceedingJoinPoint joinPoint) { //i want to add this to a queue to get executed later on addToWaitList(new Callable() { @Override public call() throws Exception { joinPoint.proceed(); } }); return; } Essentially, I want to hold off the execution