[BAEL-16663] - Split or move spring-mvc-java module

This commit is contained in:
catalin-burcea 2019-12-24 16:35:22 +02:00
parent b63a8c2335
commit 9d77b85aed
33 changed files with 192 additions and 188 deletions

View File

@ -780,6 +780,7 @@
<module>spring-mobile</module>
<module>spring-mockito</module>
<module>spring-websockets</module>
<module>spring-mvc-basics-4</module>
<module>spring-mvc-forms-jsp</module>
<module>spring-mvc-forms-thymeleaf</module>
@ -1377,6 +1378,7 @@
<module>spring-mobile</module>
<module>spring-mockito</module>
<module>spring-websockets</module>
<module>spring-mvc-forms-jsp</module>
<module>spring-mvc-forms-thymeleaf</module>
<module>spring-mvc-java</module>

View File

@ -3,8 +3,9 @@
This module contains articles about Spring aspect oriented programming (AOP)
### Relevant articles
- [Implementing a Custom Spring AOP Annotation](https://www.baeldung.com/spring-aop-annotation)
- [Intro to AspectJ](https://www.baeldung.com/aspectj)
- [Spring Performance Logging](https://www.baeldung.com/spring-performance-logging)
- [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)

View File

@ -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
public class Foo {

View File

@ -1,4 +1,4 @@
package com.baeldung.aop;
package com.baeldung.pointcutadvice;
import org.aspectj.lang.JoinPoint;
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() {
}
@Pointcut("within(com.baeldung..*) && @annotation(com.baeldung.aop.annotations.Loggable)")
@Pointcut("within(com.baeldung..*) && @annotation(com.baeldung.pointcutadvice.annotations.Loggable)")
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() {
}

View File

@ -1,4 +1,4 @@
package com.baeldung.aop;
package com.baeldung.pointcutadvice;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
@ -15,7 +15,7 @@ public class PerformanceAspect {
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() {
}

View File

@ -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.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
@ -20,11 +20,11 @@ public class PublishingAspect {
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() {
}
@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() {
}

View File

@ -1,4 +1,4 @@
package com.baeldung.aop.annotations;
package com.baeldung.pointcutadvice.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;

View File

@ -1,4 +1,4 @@
package com.baeldung.aop.annotations;
package com.baeldung.pointcutadvice.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;

View File

@ -1,7 +1,7 @@
package com.baeldung.dao;
package com.baeldung.pointcutadvice.dao;
import com.baeldung.aop.annotations.Loggable;
import com.baeldung.model.Foo;
import com.baeldung.pointcutadvice.Foo;
import com.baeldung.pointcutadvice.annotations.Loggable;
import org.springframework.stereotype.Repository;
@Repository

View File

@ -1,4 +1,4 @@
package com.baeldung.events;
package com.baeldung.pointcutadvice.events;
import org.springframework.context.ApplicationEvent;

View File

@ -1,4 +1,4 @@
package com.baeldung.events;
package com.baeldung.pointcutadvice.events;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

View File

@ -7,8 +7,8 @@
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.2.xsd">
<bean id="perfomanceMeter" class="com.baeldung.aop.PerformanceAspect"/>
<bean id="fooDao" class="com.baeldung.dao.FooDao"/>
<bean id="perfomanceMeter" class="com.baeldung.pointcutadvice.PerformanceAspect"/>
<bean id="fooDao" class="com.baeldung.pointcutadvice.dao.FooDao"/>
<aop:config>
<aop:pointcut id="anyDaoMethod" expression="@target(org.springframework.stereotype.Repository)"/>

View File

@ -1,11 +1,11 @@
package com.baeldung.config;
package com.baeldung;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
@Configuration
@ComponentScan(basePackages = { "com.baeldung.dao", "com.baeldung.aop", "com.baeldung.events" })
@ComponentScan(basePackages = { "com.baeldung.pointcutadvice" })
@EnableAspectJAutoProxy
public class TestConfig {
}

View File

@ -1,8 +1,7 @@
package com.baeldung.aop;
package com.baeldung.pointcutadvice;
import com.baeldung.config.TestConfig;
import com.baeldung.dao.FooDao;
import com.baeldung.model.Foo;
import com.baeldung.TestConfig;
import com.baeldung.pointcutadvice.dao.FooDao;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -1,7 +1,7 @@
package com.baeldung.aop;
package com.baeldung.pointcutadvice;
import com.baeldung.config.TestConfig;
import com.baeldung.dao.FooDao;
import com.baeldung.TestConfig;
import com.baeldung.pointcutadvice.dao.FooDao;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -1,9 +1,8 @@
package com.baeldung.aop;
package com.baeldung.pointcutadvice;
import com.baeldung.config.TestConfig;
import com.baeldung.dao.FooDao;
import com.baeldung.events.FooCreationEventListener;
import com.baeldung.model.Foo;
import com.baeldung.TestConfig;
import com.baeldung.pointcutadvice.dao.FooDao;
import com.baeldung.pointcutadvice.events.FooCreationEventListener;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -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.Test;
import org.junit.runner.RunWith;
@ -21,7 +21,7 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/com/baeldung/aop/beans.xml")
@ContextConfiguration("/pointcutadvice/beans.xml")
public class AopXmlConfigPerformanceIntegrationTest {
@Before

View File

@ -7,17 +7,13 @@ This module contains articles about Spring MVC with Java configuration
The "REST With Spring" Classes: http://bit.ly/restwithspring
### 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)
- [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)
- [Introduction to HtmlUnit](https://www.baeldung.com/htmlunit)
- [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)
- [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)
- [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)

View File

@ -48,19 +48,6 @@
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</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 -->
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
@ -120,18 +107,6 @@
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
</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>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
@ -285,11 +260,8 @@
<javax.el.version>3.0.1-b09</javax.el.version>
<javax.version>4.0.1</javax.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>
<json-path.version>2.4.0</json-path.version>
<gson.version>2.8.5</gson.version>
<start-class>com.baeldung.SpringMVCApplication</start-class>
</properties>

View File

@ -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() {
}
}

View 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
View 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>

View File

@ -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);
}
}

View File

@ -1,4 +1,4 @@
package com.baeldung.spring.web.config;
package com.baeldung.sendtouser;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.server.ServerHttpRequest;

View File

@ -1,15 +1,14 @@
package com.baeldung.web.controller;
import java.security.Principal;
import java.util.Map;
package com.baeldung.sendtouser;
import com.google.gson.Gson;
import org.springframework.messaging.handler.annotation.MessageExceptionHandler;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.simp.annotation.SendToUser;
import org.springframework.stereotype.Controller;
import com.google.gson.Gson;
import java.security.Principal;
import java.util.Map;
@Controller
public class WebsocketSendToUserController {

View File

@ -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.SendTo;
import org.springframework.stereotype.Controller;

View File

@ -1,4 +1,4 @@
package com.baeldung.model;
package com.baeldung.websockets;
public class Message {

View File

@ -1,4 +1,4 @@
package com.baeldung.model;
package com.baeldung.websockets;
public class OutputMessage {

View File

@ -1,4 +1,4 @@
package com.baeldung.spring.web.config;
package com.baeldung.websockets;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;

View File

@ -1,88 +1,88 @@
<html>
<head>
<title>Chat WebSocket</title>
<script src="./js/sockjs-0.3.4.js"></script>
<script src="./js/stomp.js"></script>
<script type="text/javascript">
var stompClient = null;
function setConnected(connected) {
document.getElementById('connect').disabled = connected;
document.getElementById('disconnect').disabled = !connected;
document.getElementById('conversationDiv').style.visibility = connected ? 'visible' : 'hidden';
document.getElementById('response').innerHTML = '';
}
function connect() {
var socket = new SockJS('/spring-mvc-java/chat');
stompClient = Stomp.over(socket);
stompClient.connect({}, function(frame) {
setConnected(true);
console.log('Connected: ' + frame);
stompClient.subscribe('/topic/messages', function(messageOutput) {
showMessageOutput(JSON.parse(messageOutput.body));
});
});
}
function disconnect() {
if(stompClient != null) {
stompClient.disconnect();
}
setConnected(false);
console.log("Disconnected");
}
function sendMessage() {
var from = document.getElementById('from').value;
var text = document.getElementById('text').value;
stompClient.send("/app/chat", {}, JSON.stringify({'from':from, 'text':text}));
}
function showMessageOutput(messageOutput) {
var response = document.getElementById('response');
var p = document.createElement('p');
p.style.wordWrap = 'break-word';
p.appendChild(document.createTextNode(messageOutput.from + ": " + messageOutput.text + " (" + messageOutput.time + ")"));
response.appendChild(p);
}
</script>
</head>
<body onload="disconnect()">
<div>
<div>
<input type="text" id="from" placeholder="Choose a nickname"/>
</div>
<br />
<div>
<button id="connect" onclick="connect();">Connect</button>
<button id="disconnect" disabled="disabled" onclick="disconnect();">Disconnect</button>
</div>
<br />
<div id="conversationDiv">
<input type="text" id="text" placeholder="Write a message..."/>
<button id="sendMessage" onclick="sendMessage();">Send</button>
<p id="response"></p>
</div>
</div>
</body>
<html>
<head>
<title>Chat WebSocket</title>
<script src="./js/sockjs-0.3.4.js"></script>
<script src="./js/stomp.js"></script>
<script type="text/javascript">
var stompClient = null;
function setConnected(connected) {
document.getElementById('connect').disabled = connected;
document.getElementById('disconnect').disabled = !connected;
document.getElementById('conversationDiv').style.visibility = connected ? 'visible' : 'hidden';
document.getElementById('response').innerHTML = '';
}
function connect() {
var socket = new SockJS('/spring-mvc-java/chat');
stompClient = Stomp.over(socket);
stompClient.connect({}, function(frame) {
setConnected(true);
console.log('Connected: ' + frame);
stompClient.subscribe('/topic/messages', function(messageOutput) {
showMessageOutput(JSON.parse(messageOutput.body));
});
});
}
function disconnect() {
if(stompClient != null) {
stompClient.disconnect();
}
setConnected(false);
console.log("Disconnected");
}
function sendMessage() {
var from = document.getElementById('from').value;
var text = document.getElementById('text').value;
stompClient.send("/app/chat", {}, JSON.stringify({'from':from, 'text':text}));
}
function showMessageOutput(messageOutput) {
var response = document.getElementById('response');
var p = document.createElement('p');
p.style.wordWrap = 'break-word';
p.appendChild(document.createTextNode(messageOutput.from + ": " + messageOutput.text + " (" + messageOutput.time + ")"));
response.appendChild(p);
}
</script>
</head>
<body onload="disconnect()">
<div>
<div>
<input type="text" id="from" placeholder="Choose a nickname"/>
</div>
<br />
<div>
<button id="connect" onclick="connect();">Connect</button>
<button id="disconnect" disabled="disabled" onclick="disconnect();">Disconnect</button>
</div>
<br />
<div id="conversationDiv">
<input type="text" id="text" placeholder="Write a message..."/>
<button id="sendMessage" onclick="sendMessage();">Send</button>
<p id="response"></p>
</div>
</div>
</body>
</html>