我是Spring Transaction的新手.我发现的一些事情很奇怪,可能我确实理解了这一点.我希望在方法级别有一个事务处理,并且我在同一个类中有一个调用方法,看起来它不喜欢它,它必须从单独的类调用.我不明白这是怎么可能的.如果有人知道如何解决这个问题,我将不胜感激.我想使用相同的类来调用带注释的事务方法.
这是代码:
public class UserService {
@Transactional
public boolean addUser(String userName, String password) {
try {
// call DAO layer and adds to database.
} catch (Throwable e) {
TransactionAspectSupport.currentTransactionStatus()
.setRollbackOnly();
}
}
public boolean addUsers(List<User> users) {
for (User user : users) {
addUser(user.getUserName, user.getPassword);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Spring Security对方法进行权限检查.我想调用一个私有方法来收集一些数据发送给hasPermission()方法.以下是我想要执行的东西,我得到SpelEvaluationException,因为Spring正在寻找localPrivateMethodin MethodSecurityExpressionRoot.有没有办法实现这个目标?谢谢.
@PreAuthorize("hasPermission(new Object[]{#arg3, #localPrivateMethod(#arg1,#arg2)}, 'canDoThis')")
public long publicMethod1(long arg1, long arg2, long arg3) {}
private String localPrivateMethod(long a1, long a2) {}
Run Code Online (Sandbox Code Playgroud) 我正在使用带有Spring AOP的slf4j进行日志记录和异常目的.在某些类中有一些方法形成了一个方法链接.我能够记录第一个方法的入口和出口点,但是当这个方法调用另一个方法时,AOP只记录第一个方法的入口和出口点.我想记录每个方法的入口和退出点,@Around这里使用注释是Pseudo代码来解释我想要的是
package com.sample;
public class Test implements T{
@Override
public void show() {
System.out.println("Test.show()");
test();
}
void Test(){
//Want to log entry and exit point of this method whenever this method called by any other method
//The method may belongs to same class or different package's different class
}
Run Code Online (Sandbox Code Playgroud)
spring.xml 是这样的
<bean id="exceptionAspect" class="com.sample.ExceptionAspect"/>
<bean id="test" class="com.sample.Test"/>
Run Code Online (Sandbox Code Playgroud)
我的Advise class样子
@Aspect
public class LoggingAspect {
@Around(value="execution (* com.sample.*.*(..))||"+
"execution(* some other package.*.*(..))")
public void logAround(ProceedingJoinPoint joinPoint) …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中编写了几个Aspects.所有其他人的工作除以下情况外.
服务接口
package com.enbiso.proj.estudo.system.service;
...
public interface MessageService {
...
Message reply(Message message);
Message send(Message message);
...
}
Run Code Online (Sandbox Code Playgroud)
服务实施
package com.enbiso.proj.estudo.system.service.impl;
....
@Service("messageService")
public class MessageServiceImpl implements MessageService {
...
@Override
public Message reply(Message message) {
...
return this.send(message);
}
@Override
public Message send(Message message) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
方面
@Aspect
@Component
public class NewMessageAspect {
...
@AfterReturning(value = "execution(* com.enbiso.proj.estudo.system.service.impl.MessageServiceImpl.send(..))",
returning = "message")
public void perform(Message message){
...
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试执行该send方法时,调试点不会在方面受到影响perform.
UPDATE
我做了一些调查,发现当send从 …