气氛+春天+自动问题 [英] atmosphere + spring + autowired problems

查看:136
本文介绍了气氛+春天+自动问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个网络应用并试图整合聊天(暂时)。我正在使用Spring和Atmosphere来做到这一点。
我设法让聊天工作,但现在我似乎遇到了问题。
我在一个单独的servlet中使用@ManagedService(类似于atmosphere-chat-multiroom示例),现在我需要访问spring应用程序中的bean。对于我正在使用的其余servlet,这可以完美地工作,但是当我在Atmosphere ManagedService中执行此操作时,我处于死胡同,该服务始终返回为null。

I am developing a web app and trying to integrate a chat (for now). I am using Spring and Atmosphere to do this. I managed to get the chat working, but now I seem to have run into a problem. I am using the @ManagedService in a separate servlet (similar to the atmosphere-chat-multiroom example) and now I need to access to a bean that is inside the spring application. For the rest of the servlets that I am using, this works flawlessly, but I am at a dead end when it comes to doind this in Atmosphere ManagedService, the service is always returned as null.

有没有人知道我能做些什么?

Does anyone have any clue as to what I can do?

@ManagedService(path = "{room: [a-zA-Z][a-zA-Z_0-9]*}")
@Singleton
public class ChatRoom {
private final Logger logger = LoggerFactory.getLogger(ChatRoom.class);

private final ConcurrentHashMap<String, String> users = new ConcurrentHashMap<String, String>();
private String chatroomName;
private String mappedPath;
private BroadcasterFactory factory;
@Autowired
IFriendsServices friendServices;

@Message(encoders = { JacksonEncoder.class }, decoders = { UserDecoder.class })
public void onPrivateMessage(ChatUserMessageDTO user) throws IOException {
    String userUUID = users.get(user.getUser());
    friendServices.createChatMessage(user.getUser(), user.getSource(), user.getMessage());
    if (userUUID != null) {
        AtmosphereResource r = AtmosphereResourceFactory.getDefault().find(userUUID);
        if (r != null) {
            ChatProtocolMessageDTO m = new ChatProtocolMessageDTO(user.getSource(), user.getMessage(),
                    users.keySet(), factory.lookupAll());
            factory.lookup(mappedPath).broadcast(m, r);
        }
    }
}


推荐答案

你好,我在春天挖的时候发现了各种有趣的东西。对于非Spring托管类,请按照以下两个步骤使用autowire访问属性

hello i find vary interesting thing when i was digging in spring . for non spring managed classes follow following 2 steps to access properties using autowire

public class ChatRoom extends SpringBeanAutowiringSupport{ 

and then use @Autowire 

这篇关于气氛+春天+自动问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆