spring-aop

Is Spring @autowired not meant for non-singleton containers?

余生长醉 提交于 2019-12-18 02:22:29
问题 I have a MyTask class which implements Runnable and there can be many such objects instantiated at any given moment. There are certain properties that I would like to autowire into MyTask class. But I think that if I mark MyTask with @Component then it will become a spring-managed singleton correct? That's not what I want, I need many independent instances of this class to be run by a TaskExecutor. So my question(s): a) Am I fundamentally wrong in my understanding of @Component annotation?

Unobtrusive AOP with Spring.Net

不羁的心 提交于 2019-12-17 20:26:38
问题 I'm trying to add logging to methods decorated with an attribute using Spring.Net for AOP . Step 1: Reference 'Spring.Core', 'Spring.Aop', 'Common.Logging' Step 2: Create an advice: using AopAlliance.Intercept; namespace MyApp.Aspects { public class LoggingAdvice : IMethodInterceptor { public object Invoke(IMethodInvocation invocation) { //todo: log started object rval = invocation.Proceed(); return rval; //todo: log finished } } } Step 3: Create an attribute: using System; namespace MyApp

Spring @Transactional method - participating transaction

依然范特西╮ 提交于 2019-12-17 19:46:21
问题 in one dao I have 2 @Transactional methods. if i do not provide any explicit properties, then what will happen, if I run one method in the body of another? Both methods will run within THE SAME ONE TRANSACTION? 回答1: Proxies in Spring AOP When using Transactional, you're dealing with proxies of classes, so in this scenario: @Transactional public void doSomeThing(){ // calling this method targets a proxy doSomeThingElse(); // this method targets the actual class, not the PROXY, // so the

annotation equivalent of <aop:scoped-proxy>

青春壹個敷衍的年華 提交于 2019-12-17 15:31:09
问题 I am moving from an xml config to annoations. i want to convert a session scoped bean that is <aop:scoped-proxy> can this be done with annotations, and if not, what can i do to still keep that declaration working? edit: I am interested in doing this in Spring 2.5 回答1: in the spring context xml, do something like: <context:component-scan base-package="com.startup.failure" scoped-proxy="interfaces" /> Note that you would need to write interfaces for all classes in that package, though. 回答2: In

Aspect does not capture method from Scheduled

こ雲淡風輕ζ 提交于 2019-12-13 20:15:41
问题 Why is set aspect of an annotation not working when it is set to a method from cron. @Component public class MyClass { @Scheduled(cron = "0/5 * * * * ?") public void schedule() { myMethod("test"); } @MyAnno(cl = MyClass.class, description = "desc") private void myMethod(String text) { } } @Aspect @Component public MyAscpect { @Before("@annotation(myAnnoAnnotation)") public void myAnnoAspect(JoinPoint jp, MyAnno myAnnoAnnotation) { } 回答1: Spring AOP Here are the points you should remember

@AspectJ pointcut for execute methods of a package

*爱你&永不变心* 提交于 2019-12-13 16:33:10
问题 I want to execute a execute method in a specific package. What could be a possible pointcut for this? Note: I am using @AspectJ style Spring AOP. 回答1: Have a look here http://www.eclipse.org/aspectj/doc/released/adk15notebook/annotations-pointcuts-and-advice.html @(org.xyz..*) Matches any annotated element which has either an annotation of a type matching the type pattern (org.xyz..*) . In other words, an annotated element with an annotation that is declared in the org.xyz package or a sub

Aspect fails with ClassCastException trying to pointcut Tomcat DataSource getConnection

假装没事ソ 提交于 2019-12-13 07:06:47
问题 I need to execute several initialization statements on each borrowed connection from a Tomcat JDBC Pool. I cannot use JDBCInterceptors because pool is shared with other applications that won't need said initilization. I'm using Spring Boot 1.4.4, deploying on Tomcat 8.5.11, which has a ResourceLink in context.xml to a Resource in server.xml that defines the DataSource against a Oracle 11g Database. I'm accessing the DataSource via JNDI. As per this answer https://stackoverflow.com/a/38746398

Spring AOP Controller Executing twice

时光毁灭记忆、已成空白 提交于 2019-12-13 05:14:54
问题 My applicationContext is as follows <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=".."> <mvc:annotation-driven/> <task:annotation-driven/> <mvc:resources mapping="/resources/**" location="/resources/"/> <aop:aspectj-autoproxy /> <context:component-scan base-package="com.abc"> <context:include-filter type="aspectj" expression="com.abc.aspects.LogControllerAspect"/> </context:component-scan> <context:annotation-config /> </beans> Have 2 Aspect Java classes, LogControllerAspect (for

Need help creating a specific pointcut that utilizes a value from a method annotation

核能气质少年 提交于 2019-12-13 05:09:24
问题 I have the following method @AutoHandling(slot = FunctionalArea.PRE_MAIN_MENU) @RequestMapping(method = RequestMethod.GET) public String navigation(ModelMap model) { logger.debug("navigation"); ... //First time to the Main Menu and ID-Level is ID-1 or greater if (!callSession.getCallFlowData().isMainMenuPlayed() && callSession.getCallFlowData().getIdLevel() >= 1) { // Call Auto Handling logger.info("Call AutoHandling"); autoHandlingComponent.processAutoHandling(); } ... return forward

Spring AOP: Before method execution with Collection

冷暖自知 提交于 2019-12-13 05:03:02
问题 Case 1 (Works fine) I am trying to implement a before AOP implementation for the below method: public void setNames(List names) { this.names = names; } I tried this: <aop:pointcut id="empl" expression="execution(* com.model.Employee.set*(java.util.List)) and args(names)"/> <aop:aspect ref="aspect"> <aop:before pointcut-ref="empl" method="beforeExecutionEmpl" arg-names="names"/> </aop:aspect> And it worked. Case 2 (Does not works) But if I change the method to this (Added the Generics): public