我正在尝试遵循spring.io 的 websocket 教程。只要每个 java 文件都位于同一个包中(我设法进行端到端的 websocket 通信),一切都会正常工作。我尝试将类提取GreetingController.java到WebSocketConfig.java另一个包中。然后该应用程序将无法再通过 websocket 进行通信。服务器的控制台表明SimpleBrokerMessageHandler尚未启动。以下是工作版本和非工作版本的日志:com.example.tutorial.Application : Starting Application on DESKTOP-SOF4KJM with PID 13408com.example.tutorial.Application : No active profile set, falling back to default profiles: defaulto.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)o.apache.catalina.core.StandardService : Starting service [Tomcat]org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.24]o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContexto.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1485 mso.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'clientInboundChannelExecutor'o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'clientOutboundChannelExecutor'o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService 'messageBrokerTaskScheduler'o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'brokerChannelExecutor'o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]o.s.m.s.b.SimpleBrokerMessageHandler : Starting...o.s.m.s.b.SimpleBrokerMessageHandler : BrokerAvailabilityEvent[available=true, SimpleBrokerMessageHandler [DefaultSubscriptionRegistry[cache[0 我怎样才能让我的 SpringBoot 应用程序知道另一个包中的这个 websocket 端点,知道 是GreetingController带注释的@Controller并且去WebSocketMessageBrokerConfigurer扩展类是带注释的@Configuration& @EnableWebSocketMessageBroker?
1 回答
慕哥6287543
TA贡献1831条经验 获得超10个赞
您需要告诉 Spring Boot 在主包之外的何处查找 Spring 组件。您可以使用@ComponentScan它:
@SpringBootApplication
@ComponentScan(value = "com.example.package")
public class Example {...}
@SpringBootApplication注释为@ComponentScan但仅对子包有效。
添加回答
举报
0/150
提交
取消