Spring JPA: no way of injecting bean in JPA entities
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Mon, 25 Jul 2016 19:14:54 +0000 (21:14 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Mon, 25 Jul 2016 19:14:54 +0000 (21:14 +0200)
SpringJava/JPA/spring-jpa-resources/src/main/java/de/spring/example/rest/handler/UsernameHandler.java

index 55d99b6..a0fafc2 100644 (file)
@@ -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();
        }
 }