@Component
@ServerEndpoint(WebsocketConstants.xxx)
public class xxx{
private static volatile CopyOnWriteArraySet<Session> sessions = new CopyOnWriteArraySet<>();
private Session session;
@OnOpen
public void onOpen(Session session){
sessions.add(session);
this.session = session;
}
@OnClose
public void close(Session session){
sessions.remove(session);
}
public synchronized void send(String text){
if(!sessions.isEmpty()){
sessions.forEach(session->{
if(null != session && session.isOpen()){
session.getAsyncRemote().sendText(text);
}
});
}
}
@Transactional
@Override
public boolean update(){
//xxx
}
}
报错信息:
java.lang.IllegalStateException: Failed to register @ServerEndpoint class: class com.xxx.xxx$$EnhancerBySpringCGLIB$$xxxxx ? javax.websocket.DeploymentException: Cannot deploy POJO class [com.xxx.xxxx$$EnhancerBySpringCGLIB$$xxxxx] as it is not annotated with @ServerEndpoint
问题原因:? 代理(AOP)? ? 使用了@Transactional注解导致
使用TransactionTemplate来对事务进行回滚,问题解决
@Override
public boolean update(){
return transactionTemplate.execute(status ->{
try{
//更新操作
return true;
}catch (Exception e){
status.setRollbackOnly();
return false;
}
});
}
|