Skip to content

Commit 7e8f3e6

Browse files
forketyforkpivovarit
authored andcommitted
Code samples and tests for the article "What's New in Spring 4.3?" (eugenp#497)
* Spring 4.3 New features in Spring 4.3 * Added Spring-4.3 as a new module Added Spring-4.3 as a new module. * Adding read file Adding read file * Re-written examples as tests * Added attribute annotations and default methods
1 parent 41bf1d2 commit 7e8f3e6

42 files changed

Lines changed: 998 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<module>spring-zuul</module>
7878
<module>jsf</module>
7979
<module>xml</module>
80-
80+
<module>spring-4.3</module>
8181
<module>lombok</module>
8282
<module>redis</module>
8383

‎spring-4.3/README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
In this tutorial we cover few of the new features of Spring 4.3:
2+
3+
4+
Implicit Constructor Injection
5+
Improved Resolution of Dependency
6+
Cache Abstraction Refinements
7+
Composed @RequestMapping Variants
8+
@RequestScope, @SessionScope, @ApplicationScope annotations
9+
Libraries/Application Servers Versions Support

‎spring-4.3/pom.xml‎

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.baeldung</groupId>
7+
<artifactId>spring-4.3</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
10+
<packaging>jar</packaging>
11+
12+
<name>Spring 4.3 Demo</name>
13+
14+
<properties>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
<java.version>1.8</java.version>
17+
</properties>
18+
19+
<dependencies>
20+
21+
<dependency>
22+
<groupId>org.springframework</groupId>
23+
<artifactId>spring-core</artifactId>
24+
</dependency>
25+
26+
<dependency>
27+
<groupId>org.springframework</groupId>
28+
<artifactId>spring-context</artifactId>
29+
</dependency>
30+
31+
<dependency>
32+
<groupId>org.springframework</groupId>
33+
<artifactId>spring-webmvc</artifactId>
34+
</dependency>
35+
36+
<dependency>
37+
<groupId>org.springframework</groupId>
38+
<artifactId>spring-tx</artifactId>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>org.springframework</groupId>
43+
<artifactId>spring-jdbc</artifactId>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>javax.validation</groupId>
48+
<artifactId>validation-api</artifactId>
49+
<version>1.1.0.Final</version>
50+
</dependency>
51+
52+
<dependency>
53+
<groupId>ch.qos.logback</groupId>
54+
<artifactId>logback-classic</artifactId>
55+
<version>1.1.3</version>
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>javax.servlet</groupId>
60+
<artifactId>javax.servlet-api</artifactId>
61+
<version>3.1.0</version>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>org.springframework</groupId>
66+
<artifactId>spring-test</artifactId>
67+
<scope>test</scope>
68+
</dependency>
69+
70+
<dependency>
71+
<groupId>org.easymock</groupId>
72+
<artifactId>easymock</artifactId>
73+
<version>3.4</version>
74+
<scope>test</scope>
75+
</dependency>
76+
77+
<dependency>
78+
<groupId>junit</groupId>
79+
<artifactId>junit</artifactId>
80+
<version>4.12</version>
81+
<scope>test</scope>
82+
</dependency>
83+
84+
<dependency>
85+
<groupId>com.h2database</groupId>
86+
<artifactId>h2</artifactId>
87+
<version>1.4.190</version>
88+
<scope>test</scope>
89+
</dependency>
90+
91+
</dependencies>
92+
93+
<dependencyManagement>
94+
95+
<dependencies>
96+
97+
<dependency>
98+
<groupId>org.springframework</groupId>
99+
<artifactId>spring-framework-bom</artifactId>
100+
<version>4.3.1.RELEASE</version>
101+
<type>pom</type>
102+
<scope>import</scope>
103+
</dependency>
104+
105+
</dependencies>
106+
107+
</dependencyManagement>
108+
109+
<build>
110+
<plugins>
111+
<plugin>
112+
<groupId>org.apache.maven.plugins</groupId>
113+
<artifactId>maven-compiler-plugin</artifactId>
114+
<configuration>
115+
<source>${java.version}</source>
116+
<target>${java.version}</target>
117+
</configuration>
118+
</plugin>
119+
</plugins>
120+
</build>
121+
122+
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.spring43.attributeannotations;
2+
3+
import org.springframework.web.bind.annotation.*;
4+
5+
@RestController
6+
@RequestMapping("/test")
7+
public class AttributeAnnotationsTestController {
8+
9+
@GetMapping
10+
public String get(@SessionAttribute String login, @RequestAttribute String query) {
11+
return String.format("login = %s, query = %s", login, query);
12+
}
13+
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.baeldung.spring43.attributeannotations;
2+
3+
import javax.servlet.http.HttpServletRequest;
4+
import javax.servlet.http.HttpServletResponse;
5+
6+
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
7+
8+
public class ParamInterceptor extends HandlerInterceptorAdapter {
9+
10+
@Override
11+
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
12+
request.getSession().setAttribute("login", "john");
13+
request.setAttribute("query", "invoices");
14+
return super.preHandle(request, response, handler);
15+
}
16+
17+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.baeldung.spring43.cache;
2+
3+
import java.util.concurrent.atomic.AtomicInteger;
4+
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
public class Foo {
9+
10+
private static final Logger log = LoggerFactory.getLogger(Foo.class);
11+
12+
private static final AtomicInteger instanceCount = new AtomicInteger(0);
13+
14+
15+
private final int instanceNum;
16+
17+
public Foo() {
18+
instanceNum = instanceCount.incrementAndGet();
19+
}
20+
21+
public static int getInstanceCount() {
22+
return instanceCount.get();
23+
}
24+
25+
public void printInstanceNumber() {
26+
log.info("Foo instance number: {}", instanceNum);
27+
}
28+
29+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.spring43.cache;
2+
3+
import org.springframework.cache.annotation.Cacheable;
4+
import org.springframework.stereotype.Service;
5+
6+
@Service
7+
public class FooService {
8+
9+
@Cacheable(cacheNames = "foos", sync = true)
10+
public Foo getFoo(String id) {
11+
return new Foo();
12+
}
13+
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.baeldung.spring43.composedmapping;
2+
3+
public class Appointment {
4+
5+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.baeldung.spring43.composedmapping;
2+
3+
import java.util.Map;
4+
5+
public interface AppointmentService {
6+
7+
Map<String, Appointment> getAppointmentsForToday();
8+
9+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.baeldung.spring43.composedmapping;
2+
3+
import java.util.Map;
4+
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.stereotype.Controller;
7+
import org.springframework.web.bind.annotation.GetMapping;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
10+
@Controller
11+
@RequestMapping("/appointments")
12+
public class AppointmentsController {
13+
14+
private final AppointmentService appointmentService;
15+
16+
@Autowired
17+
public AppointmentsController(AppointmentService appointmentService) {
18+
this.appointmentService = appointmentService;
19+
}
20+
21+
@GetMapping
22+
public Map<String, Appointment> get() {
23+
return appointmentService.getAppointmentsForToday();
24+
}
25+
26+
}

0 commit comments

Comments
 (0)