From: Gustavo Martin Morcuende Date: Mon, 25 Jul 2016 19:14:54 +0000 (+0200) Subject: Spring JPA: no way of injecting bean in JPA entities X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=66c15a27766324af8386e239f29c3a88df25fd1f;p=JavaForFun Spring JPA: no way of injecting bean in JPA entities --- diff --git a/SpringJava/JPA/spring-jpa-resources/src/main/java/de/spring/example/rest/handler/UsernameHandler.java b/SpringJava/JPA/spring-jpa-resources/src/main/java/de/spring/example/rest/handler/UsernameHandler.java index 55d99b6..a0fafc2 100644 --- a/SpringJava/JPA/spring-jpa-resources/src/main/java/de/spring/example/rest/handler/UsernameHandler.java +++ b/SpringJava/JPA/spring-jpa-resources/src/main/java/de/spring/example/rest/handler/UsernameHandler.java @@ -1,6 +1,5 @@ package de.spring.example.rest.handler; -import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -9,12 +8,6 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import de.spring.example.context.UsernameThreadContext; public class UsernameHandler extends HandlerInterceptorAdapter { - private final UsernameThreadContext usernameThreadContext; - - @Inject - public UsernameHandler(UsernameThreadContext userNameThreadContext) { - this.usernameThreadContext = userNameThreadContext; - } @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) @@ -22,9 +15,9 @@ public class UsernameHandler extends HandlerInterceptorAdapter { final String userName = request.getHeader(UsernameThreadContext.USERNAME_HEADER); if (userName != null) { - usernameThreadContext.setUsername(userName); + UsernameThreadContext.setUsername(userName); } else { - usernameThreadContext.clearUsername(); + UsernameThreadContext.clearUsername(); } return super.preHandle(request, response, handler); @@ -34,6 +27,6 @@ public class UsernameHandler extends HandlerInterceptorAdapter { public void afterCompletion( HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { - usernameThreadContext.clearUsername(); + UsernameThreadContext.clearUsername(); } }