{"id":1194,"date":"2020-06-25T10:59:54","date_gmt":"2020-06-25T01:59:54","guid":{"rendered":"https:\/\/ito-u-oti.com\/?p=1194"},"modified":"2020-06-25T11:00:07","modified_gmt":"2020-06-25T02:00:07","slug":"post-1194","status":"publish","type":"post","link":"https:\/\/ito-u-oti.com\/?p=1194","title":{"rendered":"\u3010SpringBoot\u3011Interceptor\u3067Header\u60c5\u5831\u3092\u53d7\u3051\u53d6\u308a\u3001Service\u5c64\u306a\u3069\u3067\u4f7f\u7528\u3059\u308b"},"content":{"rendered":"\n<p>Header\u60c5\u5831\u3092Controller\u306eIF\u90e8\u5206\u3067\u53d7\u3051\u53d6\u308c\u3070\u3001\u666e\u901a\u306b\u5f8c\u7d9a\u306eService\u5c64\u306a\u3069\u3067\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3059\u304c\u3001\u4eca\u56de\u306fController\u3067Header\u60c5\u5831\u3092\u53d7\u3051\u53d6\u3089\u305a\u306b\u3001\u5225\u306e\u5834\u6240\u3067Header\u60c5\u5831\u3092\u683c\u7d0d\u3057\u3066\u5f8c\u7d9a\u51e6\u7406\u3067\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u65b9\u6cd5\u3092\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>Spring\u306e\u6a5f\u80fd\u3067\u3042\u308bInterceptor\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 id=\"outline__1\" class=\"wp-block-heading\">Interceptor\u3068\u306f<\/h2>\n\n\n\n<p>API\u304c\u547c\u3070\u308c\u305f\u6642\u306b\u3001Controller\u304c\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u53d7\u3051\u53d6\u3063\u3066\u51e6\u7406\u3092\u958b\u59cb\u3059\u308b\u524d\u306b\u3001\u4efb\u610f\u306e\u51e6\u7406\u3092\u631f\u3080\u3053\u3068\u304c\u3067\u304d\u308bSpring\u306e\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/qiita.com\/kazuki43zoo\/items\/757b557c05f548c6c5db#handlerinterceptor\" title=\"https:\/\/qiita.com\/kazuki43zoo\/items\/757b557c05f548c6c5db#handlerinterceptor\">Quita\u306e\u8a18\u4e8b<\/a>\u3067\u5206\u304b\u308a\u3084\u3059\u3044\u8aac\u660e\u304c\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>Interceptor\u306e\u4e3b\u306a\u7528\u9014\u3068\u3057\u3066\u306f\u3001\u300c\u51e6\u7406\u306e\u524d\u5f8c\u306b\u958b\u59cb\u30fb\u7d42\u4e86\u306e\u30ed\u30b0\u3092\u631f\u3080\u300d\u304c\u6319\u3052\u3089\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u6a5f\u80fd\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001Controller\u304b\u3089\u51e6\u7406\u304c\u59cb\u307e\u308b\u524d\u306bHeader\u60c5\u5831\u3092\u53d7\u3051\u53d6\u3063\u3066\u683c\u7d0d\u3001Controller\u4ee5\u964d\u306e\u51e6\u7406\u3067\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h2 id=\"outline__2\" class=\"wp-block-heading\">Interceptor\u306e\u5b9f\u88c5<\/h2>\n\n\n\n<h3 id=\"outline__2_1\" class=\"wp-block-heading\">HiddenHeaderInterceptor.java<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\n@RequiredArgsConstructor\npublic class HideHeaderInterceptor  extends HandlerInterceptorAdapter {\n\n    private final HideHeader hideHeader;\n\n    @Override\n    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)\n            throws Exception {\n        String headerValue = request.getHeader(&quot;hide-header&quot;);\n        if(headerValue != null){\n            hideHeader.setHideHeaderValue(headerValue);\n        }\n        return true;\n    }\n}\n<\/pre><\/div>\n\n\n<p>\u30ea\u30af\u30a8\u30b9\u30c8\u304b\u3089\u30d8\u30c3\u30c0\u30fc\u60c5\u5831\u3092\u629c\u3044\u3066\u3001DI\u3057\u3066\u3044\u308bBean\u306e\u9805\u76ee\u306b\u8a2d\u5b9a\u3057\u3066\u307e\u3059\u3002<\/p>\n\n\n\n<h3 id=\"outline__2_2\" class=\"wp-block-heading\">HideHeader.java<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\n@Data\npublic class HideHeader {\n\n    private String hideHeaderValue = null;\n\n}\n<\/pre><\/div>\n\n\n<h3 id=\"outline__2_3\" class=\"wp-block-heading\">WebMvcConfig.java<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\n\/**\n * Spring webMvc Configuration\n *\/\n\n@Slf4j\n@Configuration\npublic class WebMvcConfig implements WebMvcConfigurer {\n\n    @Override\n    public void addInterceptors(InterceptorRegistry registry) {\n        registry.addInterceptor(hideHeaderInterceptor());\n    }\n\n    @Bean\n    HideHeaderInterceptor hideHeaderInterceptor() {\n        return new HideHeaderInterceptor(hideHeader());\n    }\n\n    @Bean\n    HideHeader hideHeader() {\n        return new HideHeader();\n    }\n}\n<\/pre><\/div>\n\n\n<p>Config\u3067\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068Interceptor\u306e\u767b\u9332\u3092\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 id=\"outline__3\" class=\"wp-block-heading\">DI\u306e\u30b9\u30b3\u30fc\u30d7\u306b\u3064\u3044\u3066\u6ce8\u610f<\/h2>\n\n\n\n<p>\u3053\u3053\u3067\u4e00\u3064\u6ce8\u610f\u306a\u306e\u304c\u3001\u3053\u306e\u307e\u307e\u3060\u3068HideHeader\u306e\u30e9\u30a4\u30d5\u30b5\u30a4\u30af\u30eb\u304cSingleton\u3068\u306a\u308a\u3001Spring\u306e\u4e2d\u3067\u4f7f\u3044\u307e\u308f\u3055\u308c\u308b\u306e\u3067\u524d\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u306eHeader\u60c5\u5831\u304c\u305d\u306e\u307e\u307e\u4f7f\u3048\u3066\u3057\u307e\u3046\u3068\u3044\u3046\u554f\u984c\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u3092\u9632\u3050\u305f\u3081\u306bBean\u3078\u306e\u767b\u9332\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30e9\u30a4\u30d5\u30b5\u30a4\u30af\u30eb\u3092\u30ea\u30af\u30a8\u30b9\u30c8\u6bce\u306b\u884c\u3046\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u3066\u3042\u3052\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\n    @Bean\n    @Scope(&quot;request&quot;)\n    HideHeader hideHeader() {\n        return new HideHeader();\n    }\n<\/pre><\/div>\n\n\n<p>\u30ea\u30af\u30a8\u30b9\u30c8\u6bce\u306b\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c\u751f\u6210\u3055\u308c\u3001Header\u60c5\u5831\u304c\u6bce\u56de\u30ea\u30bb\u30c3\u30c8\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h3 id=\"outline__3_1\" class=\"wp-block-heading\">Exception\u304c\u767a\u751f\u3059\u308b<\/h3>\n\n\n\n<p>\u4e0a\u306e\u8a2d\u5b9a\u3092\u884c\u3046\u3068\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\njava.lang.IllegalStateException: Failed to load ApplicationContext\n\n\tat org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)\n\tat org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)\n\tat org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118)\n\tat org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)\n\tat org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:44)\n\tat org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246)\n\tat org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:97)\n\tat org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$invokeTestInstancePostProcessors$5(ClassTestDescriptor.java:349)\n\tat org.junit.jupiter.engine.descriptor.JupiterTestDescriptor.executeAndMaskThrowable(JupiterTestDescriptor.java:215)\n\tat org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$invokeTestInstancePostProcessors$6(ClassTestDescriptor.java:349)\n\tat java.base\/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)\n\tat java.base\/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)\n\tat java.base\/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1654)\n\tat java.base\/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)\n\tat java.base\/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)\n\tat java.base\/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:312)\n\tat java.base\/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:735)\n\tat java.base\/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:734)\n\tat java.base\/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)\n\tat org.junit.jupiter.engine.descriptor.ClassTestDescriptor.invokeTestInstancePostProcessors(ClassTestDescriptor.java:348)\n\tat org.junit.jupiter.engine.descriptor.ClassTestDescriptor.instantiateAndPostProcessTestInstance(ClassTestDescriptor.java:270)\n\tat org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$2(ClassTestDescriptor.java:259)\n\tat org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$3(ClassTestDescriptor.java:263)\n\tat java.base\/java.util.Optional.orElseGet(Optional.java:369)\n\tat org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$4(ClassTestDescriptor.java:262)\n\tat org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:82)\n\tat org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:59)\n\tat org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$0(NodeTestTask.java:83)\n\tat org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)\n\tat org.junit.platform.engine.support.hierarchical.NodeTestTask.prepare(NodeTestTask.java:83)\n\tat org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:69)\n\tat java.base\/java.util.ArrayList.forEach(ArrayList.java:1540)\n\tat org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)\n\tat org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:112)\n\tat org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)\n\tat org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)\n\tat org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)\n\tat java.base\/java.util.ArrayList.forEach(ArrayList.java:1540)\n\tat org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)\n\tat org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:112)\n\tat org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)\n\tat org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)\n\tat org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)\n\tat org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)\n\tat org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)\n\tat org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)\n\tat org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220)\n\tat org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188)\n\tat org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202)\n\tat org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181)\n\tat org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)\n\tat com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)\n\tat com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)\n\tat com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)\n\tat com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)\nCaused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hideHeaderInterceptor' defined in class path resource &#x5B;com\/example\/demo\/WebMvcConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate &#x5B;com.example.demo.interceptor.HideHeaderInterceptor]: Factory method 'hideHeaderInterceptor' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hideHeader': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.\n\tat org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627)\n\tat org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456)\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1305)\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1144)\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)\n\tat org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)\n\tat org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:849)\n\tat org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)\n\tat org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)\n\tat org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)\n\tat org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:316)\n\tat org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:127)\n\tat org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)\n\tat org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)\n\t... 54 more\nCaused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate &#x5B;com.example.demo.interceptor.HideHeaderInterceptor]: Factory method 'hideHeaderInterceptor' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hideHeader': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.\n\tat org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)\n\tat org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622)\n\t... 72 more\nCaused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hideHeader': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:365)\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)\n\tat org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.resolveBeanReference(ConfigurationClassEnhancer.java:394)\n\tat org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:366)\n\tat com.example.demo.WebMvcConfig$$EnhancerBySpringCGLIB$$72265a29.hideHeader(&amp;lt;generated&gt;)\n\tat com.example.demo.WebMvcConfig.hideHeaderInterceptor(WebMvcConfig.java:27)\n\tat com.example.demo.WebMvcConfig$$EnhancerBySpringCGLIB$$72265a29.CGLIB$hideHeaderInterceptor$1(&amp;lt;generated&gt;)\n\tat com.example.demo.WebMvcConfig$$EnhancerBySpringCGLIB$$72265a29$$FastClassBySpringCGLIB$$a57f7209.invoke(&amp;lt;generated&gt;)\n\tat org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)\n\tat org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363)\n\tat com.example.demo.WebMvcConfig$$EnhancerBySpringCGLIB$$72265a29.hideHeaderInterceptor(&amp;lt;generated&gt;)\n\tat java.base\/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat java.base\/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat java.base\/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.base\/java.lang.reflect.Method.invoke(Method.java:567)\n\tat org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)\n\t... 73 more\nCaused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.\n\tat org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131)\n\tat org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:42)\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:353)\n\t... 88 more\n<\/pre><\/div>\n\n\n<p>\u3053\u308c\u306f\u3001Spring\u306eBean\u306e\u30e9\u30a4\u30d5\u30b5\u30a4\u30af\u30eb\u304c\u30c7\u30d5\u30a9\u30eb\u30c8\u3067Singleton\u306a\u306e\u306b\u5bfe\u3057\u3066\u3001\u305d\u308c\u3088\u308a\u3082\u77ed\u3044\u30e9\u30a4\u30d5\u30b5\u30a4\u30af\u30eb\uff08\u30ea\u30af\u30a8\u30b9\u30c8\u6bce\uff09\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u767b\u9332\u3057\u3088\u3046\u3068\u3057\u3066\u3044\u308b\u305f\u3081\u8d77\u3053\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u3092\u56de\u907f\u3059\u308b\u305f\u3081\u306b\u3001Scope\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u8a2d\u5b9a\u3092\u5909\u3048\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\n    @Scope(value = WebApplicationContext.SCOPE_REQUEST,proxyMode = ScopedProxyMode.TARGET_CLASS)\n    HideHeader hideHeader() {\n        return new HideHeader();\n    }\n<\/pre><\/div>\n\n\n<h2 id=\"outline__4\" class=\"wp-block-heading\">\u53c2\u8003<\/h2>\n\n\n\n<p><a href=\"https:\/\/qiita.com\/kazuki43zoo\/items\/757b557c05f548c6c5db#spring%E6%8F%90%E4%BE%9B%E3%81%AEhandlerinterceptor%E3%81%AE%E5%AE%9F%E8%A3%85%E3%82%AF%E3%83%A9%E3%82%B9\">Spring MVC(+Spring Boot)\u4e0a\u3067\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u5171\u901a\u51e6\u7406\u306e\u5b9f\u88c5\u65b9\u6cd5\u3092\u7406\u89e3\u3059\u308b<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kazuhira-r.hatenablog.com\/entry\/20151001\/1443710113\">Spring\u306eSingleton\u306a\u7ba1\u7406Bean\u306b\u3001\u81ea\u5206\u3088\u308a\u77ed\u3044\u30e9\u30a4\u30d5\u30b5\u30a4\u30af\u30eb\u306eBean\u3092DI\u3057\u3088\u3046\u3068\u3059\u308b\u3068\uff1f<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Header\u60c5\u5831\u3092Controller\u306eIF\u90e8\u5206\u3067\u53d7\u3051\u53d6\u308c\u3070\u3001\u666e\u901a\u306b\u5f8c\u7d9a\u306eService\u5c64\u306a\u3069\u3067\u4f7f\u7528 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1197,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[275,238],"class_list":["post-1194","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring","tag-interceptor","tag-spring-boot"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/1194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1194"}],"version-history":[{"count":2,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/1194\/revisions"}],"predecessor-version":[{"id":1198,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/1194\/revisions\/1198"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/media\/1197"}],"wp:attachment":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}