atmosphere + spring + autowired problems [duplicate]

青春壹個敷衍的年華 提交于 2019-12-10 10:35:49

问题


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);
        }
    }
}

回答1:


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 


来源:https://stackoverflow.com/questions/19788421/atmosphere-spring-autowired-problems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!