小编Y.M*_*.M.的帖子

Springboot @ServerEndPoint"无法找到根WebApplicationContext."

我在使用带有@ServerEndPoint注释类的spring时遇到了麻烦

我正在使用Springboot 1.2.3,我正试图弄清楚如何拥有一个端点的单个实例

@SpringBootApplication
@EnableJpaRepositories
@EnableWebSocket
public class ApplicationServer {
    public static void main(String[] args) {
        SpringApplication.run(ApplicationServer.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

弹簧配置:

@ConditionalOnWebApplication
@Configuration
public class WebSocketConfigurator {

    @Bean
    public ServerEndPoint serverEndpoint() {
        return new ServerEndPoint();
    }

    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }
}
Run Code Online (Sandbox Code Playgroud)

WebSocket端点:

@ServerEndpoint(value = "/", decoders = MessageDecoder.class, 
encoders = MessageEncoder.class, configurator = SpringConfigurator.class)
public class ServerEndPoint {

    private static final Logger LOG = LoggerFactory.getLogger(ServerEndPoint.class);

    public static final Set<CommunicationObserver> OBSERVERS = Sets.newConcurrentHashSet();

    @OnMessage
    public void …
Run Code Online (Sandbox Code Playgroud)

java spring websocket spring-boot jsr356

7
推荐指数
2
解决办法
6903
查看次数

标签 统计

java ×1

jsr356 ×1

spring ×1

spring-boot ×1

websocket ×1