亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將 WebSocketMessageBrokerConfigurer 與應用程序的其余部分提取到

如何將 WebSocketMessageBrokerConfigurer 與應用程序的其余部分提取到

慕斯709654 2023-09-20 15:28:03
我正在嘗試遵循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但僅對子包有效。


查看完整回答
反對 回復 2023-09-20
  • 1 回答
  • 0 關注
  • 100 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號