Spring-Webjar路径和WebSocket

时间:2019-03-11 14:12:38

标签: spring spring-boot websocket webjars

关于使用webjars的几个基本问​​题:

  1. 我在https://www.webjars.org/上找到了我的webjar。我将其添加到我的Maven Pom中。现在我需要在我的html文件中使用它。如何找到路径以便导入?

示例:我复制了此依赖项

<dependency>
            <groupId>org.webjars</groupId>
            <artifactId>stomp-websocket</artifactId>
            <version>2.3.3-1</version>
        </dependency>

在我的html文件中,我做了:

 <script src="/webjars/sockjs-client/sockjs.min.js"></script>

当我在控制台中打开页面时,我得到:

GET http://localhost:8080/webjars/sockjs-client/sockjs.min.js net::ERR_ABORTED 404

那么,如何找到正确的路径?

  1. 第二个问题是关于网络套接字的。我一直在关注本教程:https://www.baeldung.com/websockets-spring

在其中表示添加此依赖项:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-websocket</artifactId>
    <version>4.2.4.RELEASE</version>

</dependency>

但是随后在html文件中导入以下内容:

<script src="./js/sockjs-0.3.4.js"></script>
<script src="./js/stomp.js"></script>

sockjs和stomp是否带有上面提到的依赖项?是否有该路径的原因,或者是因为它是诸如成角度或反作用之类的东西的一部分?

3。我看到有人添加这样的配置:

@Configuration

public class WebJarConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry
                .addResourceHandler("/webjars/**")
                .addResourceLocations("/webjars/");
    }
}

这是做什么的?

感谢您的帮助!

0 个答案:

没有答案