您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
1、添加依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
</dependencies>
2、配置文件读取类
@ConfigurationProperties(prefix = "gefs.socketio")
@Data
public class SocketioProperties {
private boolean enabled;
private String host;
private int port;
}
3、编写AutoConfigure类
@org.springframework.context.annotation.Configuration
@EnableConfigurationProperties(SocketioProperties.class)
@ConditionalOnProperty(prefix = "gefs.socketio", name = "enabled", havingValue = "true")
public class SocketioAutoConfiguration {
@Autowired
private SocketioProperties socketioProperties;
@Bean
public SocketIOServer socketIOServer() {
Configuration config = new Configuration();
//在本地window环境测试时用localhost
config.setHostname(socketioProperties.getHost());
config.setPort(socketioProperties.getPort());
SocketIOServer server = new SocketIOServer(config);
server.start();
return server;
}
@Bean
public SpringAnnotationScanner springAnnotationScanner(SocketIOServer socketServer) {
return new SpringAnnotationScanner(socketServer);
}
}
4、在resources/META-INF/下创建spring.factories文件并编写内容
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.aostarit.gefs.socketio.SocketioAutoConfiguration
5、编译代码(增加配置文件自动提示)
将编译好的target\classes\META-INF/spring-configuration-metadata.json文件拷贝至resources/META-INF/
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。