朋友 你好,关于你在 yii2编写swoole的websocket服务 中的文章,我看了一下,遇到个问题,希望得到您的帮助,WebSocketService中的方法sendMsg,$uri = 'wss://' . EnvHelper::get('WEBSOCKET_URL')实际内容是怎么样的??$ws = new Client($uri); 这里我实现不了。提示 Class 'WebSocket\Client' not found
朋友,您好,关于您的问题,您直接去问博主吧,发在这里他也看不到。
不知道你这个问题是否已经解决, 如果还没有解决的话:在这种情况下,Spring Initializr 没有提供您需要的一切。对于 Maven,您需要添加以下依赖项:
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator-core</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>sockjs-client</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>stomp-websocket</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.1.1-1</version>
</dependency>复制
以下清单显示了完成的pom.xml文件:
<?xml 版本="1.0" 编码="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<父>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<版本>2.6.3</版本>
<relativePath/> <!-- 从存储库中查找父级 -->
</父>
<groupId>com.example</groupId>
<artifactId>messaging-stomp-websocket-complete</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>messaging-stomp-websocket-complete</name>
<description>Spring Boot 的演示项目</description>
<属性>
<java.version>1.8</java.version>
</属性>
<依赖项>
<依赖>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</依赖>
<依赖>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator-core</artifactId>
</依赖>
<依赖>
<groupId>org.webjars</groupId>
<artifactId>sockjs-client</artifactId>
<版本>1.0.2</版本>
</依赖>
<依赖>
<groupId>org.webjars</groupId>
<artifactId>stomp-websocket</artifactId>
<版本>2.3.3</版本>
</依赖>
<依赖>
<groupId>org.webjars</groupId>
<artifactId>引导</artifactId>
<版本>3.3.7</版本>
</依赖>
<依赖>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<版本>3.1.1-1</版本>
</依赖>
<依赖>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>测试</scope>
</依赖>
</依赖>
<构建>
<插件>
<插件>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</插件>
</插件>
</build>
</项目>
如果使用 Gradle,则需要添加以下依赖项:
implementation 'org.webjars:webjars-locator-core'
implementation 'org.webjars:sockjs-client:1.0.2'
implementation 'org.webjars:stomp-websocket:2.3.3'
implementation 'org.webjars:bootstrap:3.3.7'
implementation 'org.webjars:jquery:3.1.1-1'复制
以下清单显示了完成的build.gradle文件:
插件{
id 'org.springframework.boot' 版本 '2.6.3'
id 'io.spring.dependency-management' 版本 '1.0.11.RELEASE'
标识“java”
}
组 = 'com.example'
版本 = '0.0.1-SNAPSHOT'
源兼容性 = '1.8'
存储库{
mavenCentral()
}
依赖{
实现 'org.springframework.boot:spring-boot-starter-websocket'
实施 'org.webjars:webjars-locator-core'
实施 'org.webjars:sockjs-client:1.0.2'
实现 'org.webjars:stomp-websocket:2.3.3'
实施 'org.webjars:bootstrap:3.3.7'
实施 'org.webjars:jquery:3.1.1-1'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
测试 {
使用JUnitPlatform()
}