简体   繁体   中英

Can I use the spring context in javax websocket?

I am trying to implement one javax.websocket in application and would like to use the spring context to interact with my rest of the application. Is it possible anyway? I have tried by simple auto wire of context but of no help.

You don't provide enough details to be sure but using the WebApplicationContextUtils class could give you access to your Spring context. You can use beans defined in your context but you can't use all of Spring's capabilities since you are outside of the Spring container.

If you want full Spring capabilities you might flip the problem on its head. Instead of accessing Spring from your websocket endpoint, how about integrating the websocket endpoint into Spring? See here for a basic example: Using websockets in Java using Spring 4.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM