[BAEL-16663] - Split or move spring-mvc-java module
This commit is contained in:
parent
b63a8c2335
commit
9d77b85aed
pom.xml
spring-aop
README.md
src
main
java/com/baeldung/pointcutadvice
resources/pointcutadvice
test/java/com/baeldung
spring-mvc-java
spring-websockets
2
pom.xml
2
pom.xml
@ -780,6 +780,7 @@
|
|||||||
|
|
||||||
<module>spring-mobile</module>
|
<module>spring-mobile</module>
|
||||||
<module>spring-mockito</module>
|
<module>spring-mockito</module>
|
||||||
|
<module>spring-websockets</module>
|
||||||
<module>spring-mvc-basics-4</module>
|
<module>spring-mvc-basics-4</module>
|
||||||
<module>spring-mvc-forms-jsp</module>
|
<module>spring-mvc-forms-jsp</module>
|
||||||
<module>spring-mvc-forms-thymeleaf</module>
|
<module>spring-mvc-forms-thymeleaf</module>
|
||||||
@ -1377,6 +1378,7 @@
|
|||||||
|
|
||||||
<module>spring-mobile</module>
|
<module>spring-mobile</module>
|
||||||
<module>spring-mockito</module>
|
<module>spring-mockito</module>
|
||||||
|
<module>spring-websockets</module>
|
||||||
<module>spring-mvc-forms-jsp</module>
|
<module>spring-mvc-forms-jsp</module>
|
||||||
<module>spring-mvc-forms-thymeleaf</module>
|
<module>spring-mvc-forms-thymeleaf</module>
|
||||||
<module>spring-mvc-java</module>
|
<module>spring-mvc-java</module>
|
||||||
|
@ -3,8 +3,9 @@
|
|||||||
This module contains articles about Spring aspect oriented programming (AOP)
|
This module contains articles about Spring aspect oriented programming (AOP)
|
||||||
|
|
||||||
### Relevant articles
|
### Relevant articles
|
||||||
|
|
||||||
- [Implementing a Custom Spring AOP Annotation](https://www.baeldung.com/spring-aop-annotation)
|
- [Implementing a Custom Spring AOP Annotation](https://www.baeldung.com/spring-aop-annotation)
|
||||||
- [Intro to AspectJ](https://www.baeldung.com/aspectj)
|
- [Intro to AspectJ](https://www.baeldung.com/aspectj)
|
||||||
- [Spring Performance Logging](https://www.baeldung.com/spring-performance-logging)
|
- [Spring Performance Logging](https://www.baeldung.com/spring-performance-logging)
|
||||||
- [Introduction to Spring AOP](https://www.baeldung.com/spring-aop)
|
- [Introduction to Spring AOP](https://www.baeldung.com/spring-aop)
|
||||||
|
- [Introduction to Pointcut Expressions in Spring](https://www.baeldung.com/spring-aop-pointcut-tutorial)
|
||||||
|
- [Introduction to Advice Types in Spring](https://www.baeldung.com/spring-aop-advice-tutorial)
|
@ -1,6 +1,6 @@
|
|||||||
package com.baeldung.model;
|
package com.baeldung.pointcutadvice;
|
||||||
|
|
||||||
import com.baeldung.aop.annotations.Entity;
|
import com.baeldung.pointcutadvice.annotations.Entity;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Foo {
|
public class Foo {
|
@ -1,4 +1,4 @@
|
|||||||
package com.baeldung.aop;
|
package com.baeldung.pointcutadvice;
|
||||||
|
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
@ -23,15 +23,15 @@ public class LoggingAspect {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Pointcut("within(com.baeldung..*) && execution(* com.baeldung.dao.FooDao.*(..))")
|
@Pointcut("within(com.baeldung..*) && execution(* com.baeldung.pointcutadvice.dao.FooDao.*(..))")
|
||||||
public void repositoryMethods() {
|
public void repositoryMethods() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Pointcut("within(com.baeldung..*) && @annotation(com.baeldung.aop.annotations.Loggable)")
|
@Pointcut("within(com.baeldung..*) && @annotation(com.baeldung.pointcutadvice.annotations.Loggable)")
|
||||||
public void loggableMethods() {
|
public void loggableMethods() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Pointcut("within(com.baeldung..*) && @args(com.baeldung.aop.annotations.Entity)")
|
@Pointcut("within(com.baeldung..*) && @args(com.baeldung.pointcutadvice.annotations.Entity)")
|
||||||
public void methodsAcceptingEntities() {
|
public void methodsAcceptingEntities() {
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.baeldung.aop;
|
package com.baeldung.pointcutadvice;
|
||||||
|
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.annotation.Around;
|
import org.aspectj.lang.annotation.Around;
|
||||||
@ -15,7 +15,7 @@ public class PerformanceAspect {
|
|||||||
|
|
||||||
private static Logger logger = Logger.getLogger(PerformanceAspect.class.getName());
|
private static Logger logger = Logger.getLogger(PerformanceAspect.class.getName());
|
||||||
|
|
||||||
@Pointcut("within(com.baeldung..*) && execution(* com.baeldung.dao.FooDao.*(..))")
|
@Pointcut("within(com.baeldung..*) && execution(* com.baeldung.pointcutadvice.dao.FooDao.*(..))")
|
||||||
public void repositoryClassMethods() {
|
public void repositoryClassMethods() {
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
package com.baeldung.aop;
|
package com.baeldung.pointcutadvice;
|
||||||
|
|
||||||
import com.baeldung.events.FooCreationEvent;
|
import com.baeldung.pointcutadvice.events.FooCreationEvent;
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
import org.aspectj.lang.annotation.AfterReturning;
|
import org.aspectj.lang.annotation.AfterReturning;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
@ -20,11 +20,11 @@ public class PublishingAspect {
|
|||||||
this.eventPublisher = eventPublisher;
|
this.eventPublisher = eventPublisher;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Pointcut("within(com.baeldung..*) && execution(* com.baeldung.dao.FooDao.*(..))")
|
@Pointcut("within(com.baeldung..*) && execution(* com.baeldung.pointcutadvice.dao.FooDao.*(..))")
|
||||||
public void repositoryMethods() {
|
public void repositoryMethods() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Pointcut("within(com.baeldung..*) && execution(* com.baeldung.dao.FooDao.create*(Long,..))")
|
@Pointcut("within(com.baeldung..*) && execution(* com.baeldung.pointcutadvice.dao.FooDao.create*(Long,..))")
|
||||||
public void firstLongParamMethods() {
|
public void firstLongParamMethods() {
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.baeldung.aop.annotations;
|
package com.baeldung.pointcutadvice.annotations;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
@ -1,4 +1,4 @@
|
|||||||
package com.baeldung.aop.annotations;
|
package com.baeldung.pointcutadvice.annotations;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
@ -1,7 +1,7 @@
|
|||||||
package com.baeldung.dao;
|
package com.baeldung.pointcutadvice.dao;
|
||||||
|
|
||||||
import com.baeldung.aop.annotations.Loggable;
|
import com.baeldung.pointcutadvice.Foo;
|
||||||
import com.baeldung.model.Foo;
|
import com.baeldung.pointcutadvice.annotations.Loggable;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
@ -1,4 +1,4 @@
|
|||||||
package com.baeldung.events;
|
package com.baeldung.pointcutadvice.events;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationEvent;
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.baeldung.events;
|
package com.baeldung.pointcutadvice.events;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.ApplicationListener;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
@ -7,8 +7,8 @@
|
|||||||
http://www.springframework.org/schema/aop
|
http://www.springframework.org/schema/aop
|
||||||
http://www.springframework.org/schema/aop/spring-aop-4.2.xsd">
|
http://www.springframework.org/schema/aop/spring-aop-4.2.xsd">
|
||||||
|
|
||||||
<bean id="perfomanceMeter" class="com.baeldung.aop.PerformanceAspect"/>
|
<bean id="perfomanceMeter" class="com.baeldung.pointcutadvice.PerformanceAspect"/>
|
||||||
<bean id="fooDao" class="com.baeldung.dao.FooDao"/>
|
<bean id="fooDao" class="com.baeldung.pointcutadvice.dao.FooDao"/>
|
||||||
|
|
||||||
<aop:config>
|
<aop:config>
|
||||||
<aop:pointcut id="anyDaoMethod" expression="@target(org.springframework.stereotype.Repository)"/>
|
<aop:pointcut id="anyDaoMethod" expression="@target(org.springframework.stereotype.Repository)"/>
|
@ -1,11 +1,11 @@
|
|||||||
package com.baeldung.config;
|
package com.baeldung;
|
||||||
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan(basePackages = { "com.baeldung.dao", "com.baeldung.aop", "com.baeldung.events" })
|
@ComponentScan(basePackages = { "com.baeldung.pointcutadvice" })
|
||||||
@EnableAspectJAutoProxy
|
@EnableAspectJAutoProxy
|
||||||
public class TestConfig {
|
public class TestConfig {
|
||||||
}
|
}
|
@ -1,8 +1,7 @@
|
|||||||
package com.baeldung.aop;
|
package com.baeldung.pointcutadvice;
|
||||||
|
|
||||||
import com.baeldung.config.TestConfig;
|
import com.baeldung.TestConfig;
|
||||||
import com.baeldung.dao.FooDao;
|
import com.baeldung.pointcutadvice.dao.FooDao;
|
||||||
import com.baeldung.model.Foo;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
@ -1,7 +1,7 @@
|
|||||||
package com.baeldung.aop;
|
package com.baeldung.pointcutadvice;
|
||||||
|
|
||||||
import com.baeldung.config.TestConfig;
|
import com.baeldung.TestConfig;
|
||||||
import com.baeldung.dao.FooDao;
|
import com.baeldung.pointcutadvice.dao.FooDao;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
@ -1,9 +1,8 @@
|
|||||||
package com.baeldung.aop;
|
package com.baeldung.pointcutadvice;
|
||||||
|
|
||||||
import com.baeldung.config.TestConfig;
|
import com.baeldung.TestConfig;
|
||||||
import com.baeldung.dao.FooDao;
|
import com.baeldung.pointcutadvice.dao.FooDao;
|
||||||
import com.baeldung.events.FooCreationEventListener;
|
import com.baeldung.pointcutadvice.events.FooCreationEventListener;
|
||||||
import com.baeldung.model.Foo;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
@ -1,6 +1,6 @@
|
|||||||
package com.baeldung.aop;
|
package com.baeldung.pointcutadvice;
|
||||||
|
|
||||||
import com.baeldung.dao.FooDao;
|
import com.baeldung.pointcutadvice.dao.FooDao;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -21,7 +21,7 @@ import static org.junit.Assert.assertThat;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration("/com/baeldung/aop/beans.xml")
|
@ContextConfiguration("/pointcutadvice/beans.xml")
|
||||||
public class AopXmlConfigPerformanceIntegrationTest {
|
public class AopXmlConfigPerformanceIntegrationTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
@ -7,17 +7,13 @@ This module contains articles about Spring MVC with Java configuration
|
|||||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||||
|
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
- [Introduction to Pointcut Expressions in Spring](https://www.baeldung.com/spring-aop-pointcut-tutorial)
|
|
||||||
- [Introduction to Advice Types in Spring](https://www.baeldung.com/spring-aop-advice-tutorial)
|
|
||||||
- [Integration Testing in Spring](https://www.baeldung.com/integration-testing-in-spring)
|
- [Integration Testing in Spring](https://www.baeldung.com/integration-testing-in-spring)
|
||||||
- [A Quick Guide to Spring MVC Matrix Variables](https://www.baeldung.com/spring-mvc-matrix-variables)
|
- [A Quick Guide to Spring MVC Matrix Variables](https://www.baeldung.com/spring-mvc-matrix-variables)
|
||||||
- [Intro to WebSockets with Spring](https://www.baeldung.com/websockets-spring)
|
|
||||||
- [File Upload with Spring MVC](https://www.baeldung.com/spring-file-upload)
|
- [File Upload with Spring MVC](https://www.baeldung.com/spring-file-upload)
|
||||||
- [Introduction to HtmlUnit](https://www.baeldung.com/htmlunit)
|
- [Introduction to HtmlUnit](https://www.baeldung.com/htmlunit)
|
||||||
- [Upload and Display Excel Files with Spring MVC](https://www.baeldung.com/spring-mvc-excel-files)
|
- [Upload and Display Excel Files with Spring MVC](https://www.baeldung.com/spring-mvc-excel-files)
|
||||||
- [web.xml vs Initializer with Spring](https://www.baeldung.com/spring-xml-vs-java-config)
|
- [web.xml vs Initializer with Spring](https://www.baeldung.com/spring-xml-vs-java-config)
|
||||||
- [Spring MVC @PathVariable with a dot (.) gets truncated](https://www.baeldung.com/spring-mvc-pathvariable-dot)
|
- [Spring MVC @PathVariable with a dot (.) gets truncated](https://www.baeldung.com/spring-mvc-pathvariable-dot)
|
||||||
- [A Quick Example of Spring Websockets’ @SendToUser Annotation](https://www.baeldung.com/spring-websockets-sendtouser)
|
|
||||||
- [Working with Date Parameters in Spring](https://www.baeldung.com/spring-date-parameters)
|
- [Working with Date Parameters in Spring](https://www.baeldung.com/spring-date-parameters)
|
||||||
- [A Java Web Application Without a web.xml](https://www.baeldung.com/java-web-app-without-web-xml)
|
- [A Java Web Application Without a web.xml](https://www.baeldung.com/java-web-app-without-web-xml)
|
||||||
- [The HttpMediaTypeNotAcceptableException in Spring MVC](https://www.baeldung.com/spring-httpmediatypenotacceptable)
|
- [The HttpMediaTypeNotAcceptableException in Spring MVC](https://www.baeldung.com/spring-httpmediatypenotacceptable)
|
||||||
|
@ -48,19 +48,6 @@
|
|||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>${jackson.version}</version>
|
<version>${jackson.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- AOP -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.aspectj</groupId>
|
|
||||||
<artifactId>aspectjrt</artifactId>
|
|
||||||
<version>${aspectjrt.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.aspectj</groupId>
|
|
||||||
<artifactId>aspectjweaver</artifactId>
|
|
||||||
<version>${aspectjweaver.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- common -->
|
<!-- common -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.sourceforge.htmlunit</groupId>
|
<groupId>net.sourceforge.htmlunit</groupId>
|
||||||
@ -120,18 +107,6 @@
|
|||||||
<artifactId>hibernate-validator</artifactId>
|
<artifactId>hibernate-validator</artifactId>
|
||||||
<version>${hibernate-validator.version}</version>
|
<version>${hibernate-validator.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Web socket to user example -->
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.code.gson</groupId>
|
|
||||||
<artifactId>gson</artifactId>
|
|
||||||
<version>${gson.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.glassfish</groupId>
|
<groupId>org.glassfish</groupId>
|
||||||
<artifactId>javax.el</artifactId>
|
<artifactId>javax.el</artifactId>
|
||||||
@ -285,11 +260,8 @@
|
|||||||
<javax.el.version>3.0.1-b09</javax.el.version>
|
<javax.el.version>3.0.1-b09</javax.el.version>
|
||||||
<javax.version>4.0.1</javax.version>
|
<javax.version>4.0.1</javax.version>
|
||||||
<javax-servlet-api.version>2.3.3</javax-servlet-api.version>
|
<javax-servlet-api.version>2.3.3</javax-servlet-api.version>
|
||||||
<aspectjrt.version>1.9.1</aspectjrt.version>
|
|
||||||
<aspectjweaver.version>1.9.1</aspectjweaver.version>
|
|
||||||
<htmlunit.version>2.32</htmlunit.version>
|
<htmlunit.version>2.32</htmlunit.version>
|
||||||
<json-path.version>2.4.0</json-path.version>
|
<json-path.version>2.4.0</json-path.version>
|
||||||
<gson.version>2.8.5</gson.version>
|
|
||||||
<start-class>com.baeldung.SpringMVCApplication</start-class>
|
<start-class>com.baeldung.SpringMVCApplication</start-class>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
package com.baeldung;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
import com.baeldung.config.TestConfig;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@ContextConfiguration(classes = {TestConfig.class})
|
|
||||||
public class SpringContextTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
7
spring-websockets/README.md
Normal file
7
spring-websockets/README.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
## Spring WebSockets
|
||||||
|
|
||||||
|
This module contains articles about Spring WebSockets.
|
||||||
|
|
||||||
|
### Relevant articles
|
||||||
|
- [Intro to WebSockets with Spring](https://www.baeldung.com/websockets-spring)
|
||||||
|
- [A Quick Example of Spring Websockets’ @SendToUser Annotation](https://www.baeldung.com/spring-websockets-sendtouser)
|
37
spring-websockets/pom.xml
Normal file
37
spring-websockets/pom.xml
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?xml version="1.0" encoding="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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>spring-websockets</artifactId>
|
||||||
|
<name>spring-websockets</name>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung</groupId>
|
||||||
|
<artifactId>parent-boot-2</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<relativePath>../parent-boot-2</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>spring-websockets</finalName>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.baeldung;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class SpringBootApp extends SpringBootServletInitializer {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(SpringBootApp.class, args);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.baeldung.spring.web.config;
|
package com.baeldung.sendtouser;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.server.ServerHttpRequest;
|
import org.springframework.http.server.ServerHttpRequest;
|
@ -1,15 +1,14 @@
|
|||||||
package com.baeldung.web.controller;
|
package com.baeldung.sendtouser;
|
||||||
|
|
||||||
import java.security.Principal;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
import org.springframework.messaging.handler.annotation.MessageExceptionHandler;
|
import org.springframework.messaging.handler.annotation.MessageExceptionHandler;
|
||||||
import org.springframework.messaging.handler.annotation.MessageMapping;
|
import org.springframework.messaging.handler.annotation.MessageMapping;
|
||||||
import org.springframework.messaging.handler.annotation.Payload;
|
import org.springframework.messaging.handler.annotation.Payload;
|
||||||
import org.springframework.messaging.simp.annotation.SendToUser;
|
import org.springframework.messaging.simp.annotation.SendToUser;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import java.security.Principal;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class WebsocketSendToUserController {
|
public class WebsocketSendToUserController {
|
@ -1,7 +1,5 @@
|
|||||||
package com.baeldung.web.controller;
|
package com.baeldung.websockets;
|
||||||
|
|
||||||
import com.baeldung.model.Message;
|
|
||||||
import com.baeldung.model.OutputMessage;
|
|
||||||
import org.springframework.messaging.handler.annotation.MessageMapping;
|
import org.springframework.messaging.handler.annotation.MessageMapping;
|
||||||
import org.springframework.messaging.handler.annotation.SendTo;
|
import org.springframework.messaging.handler.annotation.SendTo;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
@ -1,4 +1,4 @@
|
|||||||
package com.baeldung.model;
|
package com.baeldung.websockets;
|
||||||
|
|
||||||
public class Message {
|
public class Message {
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.baeldung.model;
|
package com.baeldung.websockets;
|
||||||
|
|
||||||
public class OutputMessage {
|
public class OutputMessage {
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.baeldung.spring.web.config;
|
package com.baeldung.websockets;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
|
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
|
@ -1,88 +1,88 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Chat WebSocket</title>
|
<title>Chat WebSocket</title>
|
||||||
|
|
||||||
<script src="./js/sockjs-0.3.4.js"></script>
|
<script src="./js/sockjs-0.3.4.js"></script>
|
||||||
<script src="./js/stomp.js"></script>
|
<script src="./js/stomp.js"></script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
var stompClient = null;
|
var stompClient = null;
|
||||||
|
|
||||||
function setConnected(connected) {
|
function setConnected(connected) {
|
||||||
|
|
||||||
document.getElementById('connect').disabled = connected;
|
document.getElementById('connect').disabled = connected;
|
||||||
document.getElementById('disconnect').disabled = !connected;
|
document.getElementById('disconnect').disabled = !connected;
|
||||||
document.getElementById('conversationDiv').style.visibility = connected ? 'visible' : 'hidden';
|
document.getElementById('conversationDiv').style.visibility = connected ? 'visible' : 'hidden';
|
||||||
document.getElementById('response').innerHTML = '';
|
document.getElementById('response').innerHTML = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function connect() {
|
function connect() {
|
||||||
|
|
||||||
var socket = new SockJS('/spring-mvc-java/chat');
|
var socket = new SockJS('/spring-mvc-java/chat');
|
||||||
stompClient = Stomp.over(socket);
|
stompClient = Stomp.over(socket);
|
||||||
|
|
||||||
stompClient.connect({}, function(frame) {
|
stompClient.connect({}, function(frame) {
|
||||||
|
|
||||||
setConnected(true);
|
setConnected(true);
|
||||||
console.log('Connected: ' + frame);
|
console.log('Connected: ' + frame);
|
||||||
stompClient.subscribe('/topic/messages', function(messageOutput) {
|
stompClient.subscribe('/topic/messages', function(messageOutput) {
|
||||||
|
|
||||||
showMessageOutput(JSON.parse(messageOutput.body));
|
showMessageOutput(JSON.parse(messageOutput.body));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function disconnect() {
|
function disconnect() {
|
||||||
|
|
||||||
if(stompClient != null) {
|
if(stompClient != null) {
|
||||||
stompClient.disconnect();
|
stompClient.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
setConnected(false);
|
setConnected(false);
|
||||||
console.log("Disconnected");
|
console.log("Disconnected");
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendMessage() {
|
function sendMessage() {
|
||||||
|
|
||||||
var from = document.getElementById('from').value;
|
var from = document.getElementById('from').value;
|
||||||
var text = document.getElementById('text').value;
|
var text = document.getElementById('text').value;
|
||||||
stompClient.send("/app/chat", {}, JSON.stringify({'from':from, 'text':text}));
|
stompClient.send("/app/chat", {}, JSON.stringify({'from':from, 'text':text}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function showMessageOutput(messageOutput) {
|
function showMessageOutput(messageOutput) {
|
||||||
|
|
||||||
var response = document.getElementById('response');
|
var response = document.getElementById('response');
|
||||||
var p = document.createElement('p');
|
var p = document.createElement('p');
|
||||||
p.style.wordWrap = 'break-word';
|
p.style.wordWrap = 'break-word';
|
||||||
p.appendChild(document.createTextNode(messageOutput.from + ": " + messageOutput.text + " (" + messageOutput.time + ")"));
|
p.appendChild(document.createTextNode(messageOutput.from + ": " + messageOutput.text + " (" + messageOutput.time + ")"));
|
||||||
response.appendChild(p);
|
response.appendChild(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body onload="disconnect()">
|
<body onload="disconnect()">
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<input type="text" id="from" placeholder="Choose a nickname"/>
|
<input type="text" id="from" placeholder="Choose a nickname"/>
|
||||||
</div>
|
</div>
|
||||||
<br />
|
<br />
|
||||||
<div>
|
<div>
|
||||||
<button id="connect" onclick="connect();">Connect</button>
|
<button id="connect" onclick="connect();">Connect</button>
|
||||||
<button id="disconnect" disabled="disabled" onclick="disconnect();">Disconnect</button>
|
<button id="disconnect" disabled="disabled" onclick="disconnect();">Disconnect</button>
|
||||||
</div>
|
</div>
|
||||||
<br />
|
<br />
|
||||||
<div id="conversationDiv">
|
<div id="conversationDiv">
|
||||||
<input type="text" id="text" placeholder="Write a message..."/>
|
<input type="text" id="text" placeholder="Write a message..."/>
|
||||||
<button id="sendMessage" onclick="sendMessage();">Send</button>
|
<button id="sendMessage" onclick="sendMessage();">Send</button>
|
||||||
<p id="response"></p>
|
<p id="response"></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
x
Reference in New Issue
Block a user