{"id":657,"date":"2019-02-03T20:05:02","date_gmt":"2019-02-03T11:05:02","guid":{"rendered":"https:\/\/ito-u-oti.com\/?p=657"},"modified":"2019-02-03T20:13:36","modified_gmt":"2019-02-03T11:13:36","slug":"post-657","status":"publish","type":"post","link":"https:\/\/ito-u-oti.com\/?p=657","title":{"rendered":"@Scope(&#8220;step&#8221;)\u306e\u30c6\u30b9\u30c8\u3067\u30a8\u30e9\u30fc\uff08No context holder available for step scope\uff09"},"content":{"rendered":"<h2 id=\"outline__1\">\u4e8b\u8c61<\/h2>\n<p>@Scope(&#8220;step&#8221;)\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u304c\u4ed8\u4e0e\u3055\u308c\u3066\u3044\u308b\u30af\u30e9\u30b9\u306b\u5bfe\u3057\u3066Junit\u306b\u3088\u308bSpringJUnit4ClassRunner\u30c6\u30b9\u30c8\u3092\u4f5c\u6210\u3057\u5b9f\u884c\u3057\u305f\u3068\u3053\u308d\u30a8\u30e9\u30fc\u304c\u767a\u751f<\/p>\n<h2 id=\"outline__2\">\u30a8\u30e9\u30fc\u5185\u5bb9<\/h2>\n<p>\u30c6\u30b9\u30c8\u5bfe\u8c61\u5b9f\u88c5\u30af\u30e9\u30b9<br \/>\nSharedServiceImpl<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n@Service\r\n@Scope(&quot;step&quot;)\r\npublic class SharedServiceImpl implements SharedService {\r\n\r\n    \/**\r\n     * Long\u578b\u306e\u6570\u5024\u3092\u30ab\u30f3\u30de\u7de8\u96c6\u3057\u3066\u8fd4\u3059\r\n     * @param value \u7de8\u96c6\u524d\u6570\u5024\r\n     * @return \u30ab\u30f3\u30de\u7de8\u96c6\u5f8c\u6587\u5b57\u5217\r\n     *\/\r\n    @Override\r\n    public String longToConma(long value) {\r\n\r\n        NumberFormat conmaFormat = NumberFormat.getNumberInstance();\r\n\r\n        return conmaFormat.format(value);\r\n    }\r\n}\r\n<\/pre>\n<p>\u30c6\u30b9\u30c8\u30af\u30e9\u30b9<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n@RunWith(SpringJUnit4ClassRunner.class)\r\n@ContextConfiguration(locations = { &quot;classpath:META-INF\/spring\/shareService.xml&quot; })\r\npublic class SharedService_longToconmaTest {\r\n\r\n    @Inject\r\n    SharedService target;\r\n\r\n    \/**\r\n     * \u30c6\u30b9\u30c8\u672c\u4f53\r\n     *\/\r\n    @Test\r\n    public void test() {\r\n\r\n        long testNum = 9999999999L;\r\n\r\n        String actual = target.longToConma(testNum);\r\n\r\n        assertThat(actual, is(&quot;9,999,999,999&quot;));\r\n    }\r\n\r\n}\r\n<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\norg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.sharedServiceImpl': Scope 'step' 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 context holder available for step scope\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:355)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)\r\n\tat org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)\r\n\tat org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:192)\r\n\tat com.sun.proxy.$Proxy16.longToConma(Unknown Source)\r\n\tat itouoti.spring.batch.service.sharedService.SharedService_longToconmaTest.test(SharedService_longToconmaTest.java:29)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat java.lang.reflect.Method.invoke(Method.java:498)\r\n\tat org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)\r\n\tat org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\r\n\tat org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)\r\n\tat org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\r\n\tat org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)\r\n\tat org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)\r\n\tat org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)\r\n\tat org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)\r\n\tat org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)\r\n\tat org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)\r\n\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\r\n\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\r\n\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\r\n\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\r\n\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\r\n\tat org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)\r\n\tat org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)\r\n\tat org.junit.runners.ParentRunner.run(ParentRunner.java:363)\r\n\tat org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)\r\n\tat org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)\r\n\tat org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)\r\n\tat org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)\r\n\tat org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)\r\n\tat org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)\r\n\tat org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)\r\nCaused by: java.lang.IllegalStateException: No context holder available for step scope\r\n\tat org.springframework.batch.core.scope.StepScope.getContext(StepScope.java:167)\r\n\tat org.springframework.batch.core.scope.StepScope.get(StepScope.java:99)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:340)\r\n\t... 34 more\r\n<\/pre>\n<h2 id=\"outline__3\">\u539f\u56e0<\/h2>\n<p>@Scope(&#8220;step&#8221;)\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u304c\u4ed8\u4e0e\u3055\u308c\u3066\u3044\u308b\u30af\u30e9\u30b9\u306b\u5bfe\u3057\u3066DI\u6a5f\u80fd\u3092\u5229\u7528\u3057\u305f\u30c6\u30b9\u30c8\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u305f\u305f\u3081\u3002<\/p>\n<h2 id=\"outline__4\">\u89e3\u6c7a\u7b56<\/h2>\n<p>@TestExecutionListeners\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3067\u4ee5\u4e0b\u306e\u30af\u30e9\u30b9\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u30a8\u30e9\u30fc\u3092\u56de\u907f\u3067\u304d\u308b\u3002<br \/>\n\u30fbDependencyInjectionTestExecutionListener<br \/>\n\u30fbStepScopeTestExecutionListener<\/p>\n<p>\u30c6\u30b9\u30c8\u30af\u30e9\u30b9<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n@RunWith(SpringJUnit4ClassRunner.class)\r\n@ContextConfiguration(locations = { &quot;classpath:META-INF\/spring\/shareService.xml&quot; })\r\n@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class,\r\n    StepScopeTestExecutionListener.class})\r\npublic class SharedService_longToconmaTest {\r\n\r\n    @Inject\r\n    SharedService target;\r\n\r\n    \/**\r\n     * \u30c6\u30b9\u30c8\u672c\u4f53\r\n     *\/\r\n    @Test\r\n    public void test() {\r\n\r\n        long testNum = 9999999999L;\r\n\r\n        String actual = target.longToConma(testNum);\r\n\r\n        assertThat(actual, is(&quot;9,999,999,999&quot;));\r\n    }\r\n\r\n}\r\n<\/pre>\n<h2 id=\"outline__5\">\u53c2\u8003<\/h2>\n<p><a href=\"http:\/\/forum.spring.io\/forum\/spring-projects\/batch\/76317-jdbccursoritemreader-test-fails-on-step-scope\">JdbcCursorItemReader test fails on step scope<\/a><br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/28457107\/spring-batch-scope-issue-while-using-spring-boot\">Spring batch scope issue while using spring boot<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e8b\u8c61 @Scope(&#8220;step&#8221;)\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u304c\u4ed8\u4e0e\u3055\u308c\u3066\u3044\u308b\u30af\u30e9\u30b9\u306b\u5bfe\u3057 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":93,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[154,152,149,153],"class_list":["post-657","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-error-bugs","tag-scope","tag-beancreationexception","tag-spring-batch","tag-step"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/657","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=657"}],"version-history":[{"count":4,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/657\/revisions"}],"predecessor-version":[{"id":661,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/657\/revisions\/661"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/media\/93"}],"wp:attachment":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=657"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}