First,forgive my poor English,I am just working hard on my English:).
I'm trying to find a easy way to set the communication more simple between front-end and back-end,because I use ActiveMQ as the Message Oriented Middleware.so XML string became the request carrier.
for example,front-end send a string request to back-end including package name,class name,method name and parameters list,in this way,back-end is allowed to invoke the correct method by these information,and send invoke result back to front-end.it works,but not perfect.the problem is that when I tried to invoke a method in a service class with @transational and @service annotation(which is the common practice to connect to the database),the transaction seemed not being opened,request and response are both received,just left a lot of sleeping connetion in mysql database process,as much as the ActiveMQ's consumers every time.
target method in service class:
@Service
@Transactional
public class UserService {
@Autowired
private IUserDAO udao;
public User getUserByName(String username) {
return udao.findByUsername(username);
}
}
invoke method(some code has been omitted):
@Component
public class ReflectTool {
public Object invokeMethod(String packageName,String className,String methodName,List paramList) {
BeanFactory beanFactory = new ClassPathXmlApplicationContext("applicationContext.xml");
Object obj = beanFactory.getBean(packageName+"."+className);
Class cla = obj.getClass();
Method method = findMethod(Class cla,String methodName);
return method.invoke(obj, params);
}
}
I've serached a lot answer,but none of them worked.like:use a proxy object to invoke but not the target object,cause spring framework has used a proxy class instead the service class with @transactional annotation to help we manager the transaction,but the code(AopUtils.isAopProxy(obj)) returns true,so it mean the object is exactly a proxy object which I got from the spring context?I'm not very familiar with Dynamic Agent Model.
Thanks for your attention,please tell me if I did something wrong.
Aucun commentaire:
Enregistrer un commentaire