From 66c15a27766324af8386e239f29c3a88df25fd1f Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Mon, 25 Jul 2016 21:14:54 +0200 Subject: [PATCH] Spring JPA: no way of injecting bean in JPA entities --- .../de/spring/example/rest/handler/UsernameHandler.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) 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(); } } -- 2.1.4