spring boot webscoket基本配置
2016-08-05 00:00
549 查看
摘要: 进行websocket的最基本配置,
后续进行完善
后续进行完善
一、pom.xml文件配置 <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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.hxkj.websocket</groupId> <artifactId>springboot-websocket</artifactId> <version>0.0.1-SNAPSHOT</version> <!-- Inherit defaults from Spring Boot --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.0.RELEASE</version> </parent> <!-- Add typical dependencies for a web application --> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--Mysql --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!-- datajpa --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> <!-- websocket --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> </dependencies> <!-- Package as an executable jar --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 可能需要翻墙 二、application.java启动配置、 @EnableTransactionManagement @SpringBootApplication @ServletComponentScan//servlet的扫描 public class Application extends SpringBootServletInitializer { private static Logger logger = Logger.getLogger(Application.class); @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(Application.class); } public static void main(String[] args) { SpringApplication.run(Application.class, args); logger.info("============= SpringBoot Start Success ============="); } } 三、websocket基本配置 @Configuration @EnableWebSocketMessageBroker public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { @Override public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/socket").withSockJS(); } @Override public void configureMessageBroker(MessageBrokerRegistry registry) { registry.enableSimpleBroker("/topic"); registry.setApplicationDestinationPrefixes("/app"); } } 四、controller配置 @Controller public class GreetingController { @Autowired private SimpMessagingTemplate simpMessagingTemplate; @RequestMapping("index") public String index(){ return "index"; } @RequestMapping("/helloSocket") public String helloSocket(){ return "hello/index"; } @MessageMapping(value="/change-notice") @SendTo("/topic/notice") public void greeting(String value){ System.out.println("session:"+" value:"+value); this.simpMessagingTemplate.convertAndSend("/topic/notice", value); } }
相关文章推荐
- 使用springboot配置webscoket
- spring boot web相关配置
- Spring整合Structs2 的web.xml 基本配置
- Spring Boot WEB相关配置
- Spring Boot学习进阶笔记(一)-初体验,创建基本的web功能
- IDE 用Spring Boot零配置快速创建web项目(1)
- spring boot web相关配置
- Spring Boot + Jpa(Hibernate) 架构基本配置
- Springboot-webscoket with sockjs
- SpringBoot基本讲解(配置文件)
- 一起学JAVA之《spring boot》03 - 开始spring boot基本配置及项目结构
- spring boot web相关配置
- Spring Boot + Mybatis + Ehcache架构基本配置
- Spring Boot + Jpa(Hibernate) 架构基本配置详解
- spring 在web项目中的一些基本配置
- Spring Boot应用基本配置说明
- spring 配置一个基本的web项目
- springboot webmvc 自动配置
- Spring Boot入门——web相关配置
- 使用Gradle构建SpringBoot工程系列:第四篇:项目初始化(编辑build.gradle文件,引入项目基本配置及依赖)