Create a public utils class
[Java]View PlainCopy
- Applicationcontextregister
[Java]View PlainCopy
- @Component
- @Lazy (false)
- Public class Applicationcontextregister implements Applicationcontextaware {
- private static ApplicationContext Application_context;
- /**
- * Set Spring Context * * @param applicationcontext Spring context * @throws beansexception
- */
- @Override
- public void Setapplicationcontext (ApplicationContext applicationcontext) throws beansexception {
- Application_context = ApplicationContext;
- }
- public static ApplicationContext Getapplicationcontext () {
- return application_context;
- }
- }
[Java]View PlainCopy
- WebSocket using the service layer
- ApplicationContext act = applicationcontextregister.getapplicationcontext ();
- Messagelogservice=act.getbean (Messagelogservice. Class);
- int resultlog = Messagelogservice.insertintomessagelog (MessageLog);
You can use the method in the service!!
Methods of using service layer in WebSocket