Moved spring-4.3 project into spring-all (#500)

* Moved spring-4.3 project into spring-all

* Removed spring-4.3 project
This commit is contained in:
Sergey Petunin
2016-07-14 19:27:31 +06:00
committed by Grzegorz Piwowarek
parent eb1afcbb2c
commit b5a3fabb75
46 changed files with 86 additions and 217 deletions
@@ -0,0 +1,14 @@
package org.baeldung.spring43.attributeannotations;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/test")
public class AttributeAnnotationsTestController {
@GetMapping
public String get(@SessionAttribute String login, @RequestAttribute String query) {
return String.format("login = %s, query = %s", login, query);
}
}
@@ -0,0 +1,17 @@
package org.baeldung.spring43.attributeannotations;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
public class ParamInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
request.getSession().setAttribute("login", "john");
request.setAttribute("query", "invoices");
return super.preHandle(request, response, handler);
}
}
@@ -0,0 +1,29 @@
package org.baeldung.spring43.cache;
import java.util.concurrent.atomic.AtomicInteger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Foo {
private static final Logger log = LoggerFactory.getLogger(Foo.class);
private static final AtomicInteger instanceCount = new AtomicInteger(0);
private final int instanceNum;
public Foo() {
instanceNum = instanceCount.incrementAndGet();
}
public static int getInstanceCount() {
return instanceCount.get();
}
public void printInstanceNumber() {
log.info("Foo instance number: {}", instanceNum);
}
}
@@ -0,0 +1,14 @@
package org.baeldung.spring43.cache;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
@Service
public class FooService {
@Cacheable(cacheNames = "foos", sync = true)
public Foo getFoo(String id) {
return new Foo();
}
}
@@ -0,0 +1,5 @@
package org.baeldung.spring43.composedmapping;
public class Appointment {
}
@@ -0,0 +1,9 @@
package org.baeldung.spring43.composedmapping;
import java.util.Map;
public interface AppointmentService {
Map<String, Appointment> getAppointmentsForToday();
}
@@ -0,0 +1,26 @@
package org.baeldung.spring43.composedmapping;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/appointments")
public class AppointmentsController {
private final AppointmentService appointmentService;
@Autowired
public AppointmentsController(AppointmentService appointmentService) {
this.appointmentService = appointmentService;
}
@GetMapping
public Map<String, Appointment> get() {
return appointmentService.getAppointmentsForToday();
}
}
@@ -0,0 +1,5 @@
package org.baeldung.spring43.ctor;
public class FooRepository {
}
@@ -0,0 +1,15 @@
package org.baeldung.spring43.ctor;
public class FooService {
private final FooRepository repository;
public FooService(FooRepository repository) {
this.repository = repository;
}
public FooRepository getRepository() {
return repository;
}
}
@@ -0,0 +1,18 @@
package org.baeldung.spring43.defaultmethods;
import java.time.LocalDate;
public class DateHolder implements IDateHolder {
private LocalDate localDate;
@Override
public LocalDate getLocalDate() {
return localDate;
}
@Override
public void setLocalDate(LocalDate localDate) {
this.localDate = localDate;
}
}
@@ -0,0 +1,16 @@
package org.baeldung.spring43.defaultmethods;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public interface IDateHolder {
LocalDate getLocalDate();
void setLocalDate(LocalDate localDate);
default void setStringDate(String stringDate) {
setLocalDate(LocalDate.parse(stringDate, DateTimeFormatter.ofPattern("dd.MM.yyyy")));
}
}
@@ -0,0 +1,8 @@
package org.baeldung.spring43.depresolution;
import org.springframework.stereotype.Repository;
@Repository
public class FooRepository {
}
@@ -0,0 +1,18 @@
package org.baeldung.spring43.depresolution;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.stereotype.Service;
@Service
public class FooService {
private final FooRepository repository;
public FooService(ObjectProvider<FooRepository> repositoryProvider) {
this.repository = repositoryProvider.getIfUnique();
}
public FooRepository getRepository() {
return repository;
}
}
@@ -0,0 +1,10 @@
package org.baeldung.spring43.scopeannotations;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.ApplicationScope;
@Component
@ApplicationScope
public class AppPreferences extends InstanceCountingService {
}
@@ -0,0 +1,15 @@
package org.baeldung.spring43.scopeannotations;
import java.util.concurrent.atomic.AtomicInteger;
public class InstanceCountingService {
private static final AtomicInteger instanceCount = new AtomicInteger(0);
private final int instanceNumber = instanceCount.incrementAndGet();
public int getInstanceNumber() {
return instanceNumber;
}
}
@@ -0,0 +1,10 @@
package org.baeldung.spring43.scopeannotations;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
@Component
@RequestScope
public class LoginAction extends InstanceCountingService {
}
@@ -0,0 +1,36 @@
package org.baeldung.spring43.scopeannotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/appointments")
public class ScopeTestController {
@Autowired
private LoginAction loginAction;
@Autowired
private UserPreferences userPreferences;
@Autowired
private AppPreferences appPreferences;
@GetMapping("/request")
public String getRequestNumber() {
return Integer.toString(loginAction.getInstanceNumber());
}
@GetMapping("/session")
public String getSessionNumber() {
return Integer.toString(userPreferences.getInstanceNumber());
}
@GetMapping("/application")
public String getApplicationNumber() {
return Integer.toString(appPreferences.getInstanceNumber());
}
}
@@ -0,0 +1,10 @@
package org.baeldung.spring43.scopeannotations;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.SessionScope;
@Component
@SessionScope
public class UserPreferences extends InstanceCountingService {
}