dynamic-proxy

Self-invocation behaviour in @Configuration vs. @Component classes

 ̄綄美尐妖づ 提交于 2020-02-22 07:46:48
问题 My question is about AOP Spring behaviour in case of internal method calls. @Service class Service { @Transactional public void method1() { method1(); } @Transactional public void method2() {} } If we call method1() from outside, method1() will be executed in a transaction mode, but as it calls internally method2(), the code inside method2() will not be executed in a transaction mode. In parallel, for a Configuration class, normally we should have the same behaviour: @Configuration class

Self-invocation behaviour in @Configuration vs. @Component classes

痴心易碎 提交于 2020-02-22 07:46:45
问题 My question is about AOP Spring behaviour in case of internal method calls. @Service class Service { @Transactional public void method1() { method1(); } @Transactional public void method2() {} } If we call method1() from outside, method1() will be executed in a transaction mode, but as it calls internally method2(), the code inside method2() will not be executed in a transaction mode. In parallel, for a Configuration class, normally we should have the same behaviour: @Configuration class

How do I replace a method implementation at runtime?

这一生的挚爱 提交于 2020-01-09 08:11:19
问题 I'd like to have property getters and methods that I can decorate with my own custom attribute and based on the presence of that attribute replace the method bodies with a different implementation. Also, that different implementation will need to know the constructor arguments given to the custom attribute where it decorates the method. This can obviously be done with AOP, like PostSharp or LinFu, but I'm wondering if there's a way to do this that does not involve a post-build processing step

How do I replace a method implementation at runtime?

微笑、不失礼 提交于 2020-01-09 08:11:05
问题 I'd like to have property getters and methods that I can decorate with my own custom attribute and based on the presence of that attribute replace the method bodies with a different implementation. Also, that different implementation will need to know the constructor arguments given to the custom attribute where it decorates the method. This can obviously be done with AOP, like PostSharp or LinFu, but I'm wondering if there's a way to do this that does not involve a post-build processing step

Why don't I experience any exception when I lookup bean wrapped by JDK dynamic proxy by class(instead of interface)?

好久不见. 提交于 2020-01-02 10:32:44
问题 Lets consider following bean: @Service @Scope(value = "prototype", proxyMode = ScopedProxyMode.INTERFACES) public class MyBeanB implements MyBeanBInterface { private static final AtomicLong COUNTER = new AtomicLong(0); private Long index; public MyBeanB() { index = COUNTER.getAndIncrement(); System.out.println("constructor invocation:" + index); } @Transactional @Override public long getCounter() { return index; } } and consider 2 different usages: USAGE 1: @Service public class MyBeanA {

Intercept Properties With Castle Windsor IInterceptor

只愿长相守 提交于 2020-01-02 07:39:37
问题 Does anyone have a suggestion on a better way to intercept a properties with Castle DynamicProxy? Specifically, I need the PropertyInfo that I'm intercepting, but it's not directly on the IInvocation, so what I do is: public static PropertyInfo GetProperty(this MethodInfo method) { bool takesArg = method.GetParameters().Length == 1; bool hasReturn = method.ReturnType != typeof(void); if (takesArg == hasReturn) return null; if (takesArg) { return method.DeclaringType.GetProperties() .Where

how to reattach singleton Spring beans upon deserialization

对着背影说爱祢 提交于 2020-01-01 09:10:10
问题 I want to reinject singleton-scoped dependencies into prototype Spring beans, after they have been deserialized. Say I've got a Process bean, which depends on a Repository bean. The Repository bean is a scoped as a singleton, but the Process bean is prototype-scoped. Periodically I serialize the Process, and then later deserialize it. class Process { private Repository repository; // getters, setters, etc. } I don't want to serialize and deserialize the Repository. Nor do I want to put

Why won't DynamicProxy's interceptor get called for *each* virtual method call?

人盡茶涼 提交于 2019-12-31 22:37:31
问题 An example explains it best : public interface IA { void foo(); void bar(); } public class A : IA { public virtual void foo(){ Console.Write("foo"); bar(); //call virtual method } public virtual void bar(){ Console.Write("bar"); } } public class Interceptor : IInterceptor { public void Intercept(IInvocation invocation) { Console.WriteLine("Intercepted: " + invocation.Method.Name); invocation.Proceed(); } } Main(){ IA a = new A(); //proxy-ing an interface, given an implementation IA proxy =

Why simple set and then get on Dynamic Proxy does not persist? (using TinkerPop Frames JavaHandler)

醉酒当歌 提交于 2019-12-25 05:27:19
问题 I wanted to add simple getters and setters on a class that implements VertexFrame and I used JavaHandlers for those. For those methods I didn't want to have any interaction with the database. Unfortunately there is not something like @Ignore so I don't have unexpected annotation exceptions. When I set something on the proxy and immediately I do a get after it goes through reflection, nothing is stored. Could be that I shouldn't be using JavaHandlers but something else.. Btw manager.frame

MassTransit: Message contracts, polymorphism and dynamic proxy objects

喜夏-厌秋 提交于 2019-12-25 04:18:09
问题 TL;DR On contract subscription, how can I get the raw message content or the original published object, rather than a dynamic proxy? I am having a bad time trying to create a modular application based on MassTransit. My idea is to have a Websocket server connected to queue, it reads events from the socket and inserts it in the queue as a "connection request", and reads events from the queue and send them to the sockets as "connection events". Both have a contract that allows the WS server