質問編集履歴

2

お礼

2018/04/17 17:00

投稿

yuki1111
yuki1111

スコア72

test CHANGED
File without changes
test CHANGED
@@ -154,30 +154,12 @@
154
154
 
155
155
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-1.5.4.RELEASE.jar:1.5.4.RELEASE]
156
156
 
157
- at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120) [spring-boot-test-1.5.4.RELEASE.jar:1.5.4.RELEASE]
157
+ at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120
158
158
 
159
- at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
160
159
 
161
- at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
162
160
 
163
- at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
164
161
 
165
- at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:189) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
166
162
 
167
- at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:131) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
163
+ mainメソッドのあるクラスに@ImportResource("ApplicationContext.xml")だったのですが、@ImportResource("classpath:ApplicationContext.xml")にしなければならなかったようです。
168
164
 
169
- at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
170
-
171
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
172
-
173
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
174
-
175
- at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.12.jar:4.12]
176
-
177
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
178
-
179
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
180
-
181
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
182
-
183
- at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) [junit-4.12.jar:4.12]
165
+ 泣きそうなくらい悩みました。質問に答えてくれてほんとうにありがとうございます。

1

ソースコードとログを載せました

2018/04/17 17:00

投稿

yuki1111
yuki1111

スコア72

test CHANGED
File without changes
test CHANGED
@@ -21,3 +21,163 @@
21
21
 
22
22
 
23
23
  どうすればアノテーションで上手く設定できるのかご教示お願い致します。
24
+
25
+
26
+
27
+ ソースコード(お見せしてはいけないものは〇に変えてあります)
28
+
29
+ ```java
30
+
31
+ package com.〇〇〇〇.service;
32
+
33
+
34
+
35
+ import static org.hamcrest.CoreMatchers.equalTo;
36
+
37
+ import static org.junit.Assert.assertThat;
38
+
39
+
40
+
41
+ import java.util.List;
42
+
43
+
44
+
45
+ import org.junit.Test;
46
+
47
+ import org.junit.runner.RunWith;
48
+
49
+ import org.springframework.boot.test.context.SpringBootTest;
50
+
51
+ import org.springframework.test.context.junit4.SpringRunner;
52
+
53
+
54
+
55
+ import com.〇〇〇〇.domain.entity.Mst002Authority;
56
+
57
+
58
+
59
+
60
+
61
+ //@RunWith(SpringJUnit4ClassRunner.class)
62
+
63
+ //@SpringBootConfiguration(GantelApplication.class)
64
+
65
+ //@ContextConfiguration(locations="classpath:ApplicationContext.xml")
66
+
67
+
68
+
69
+ @RunWith(SpringRunner.class)
70
+
71
+ @SpringBootTest
72
+
73
+ public class AuthorityServiceTest {
74
+
75
+
76
+
77
+ // @Autowired
78
+
79
+ // AuthorityService authorityService;
80
+
81
+
82
+
83
+
84
+
85
+ @Test
86
+
87
+ public void 権限を全権取得できる() {
88
+
89
+ AuthorityService authorityService = new AuthorityService();
90
+
91
+ List<Mst002Authority> list = authorityService.getAuthorityAll();
92
+
93
+ assertThat(list.get(0).getAuthorityId(), equalTo("A10"));
94
+
95
+ assertThat(list.get(0).getAuthorityName(), equalTo("〇〇"));
96
+
97
+ assertThat(list.get(1).getAuthorityId(), equalTo("A20"));
98
+
99
+ assertThat(list.get(1).getAuthorityName(), equalTo("〇〇"));
100
+
101
+ assertThat(list.get(2).getAuthorityId(), equalTo("A30"));
102
+
103
+ assertThat(list.get(2).getAuthorityName(), equalTo("〇〇"));
104
+
105
+ assertThat(list.get(3).getAuthorityId(), equalTo("A40"));
106
+
107
+ assertThat(list.get(3).getAuthorityName(), equalTo("〇〇"));
108
+
109
+ }
110
+
111
+ }
112
+
113
+ ```
114
+
115
+
116
+
117
+ 2018-04-17 01:51:25.413 ERROR 5500 --- [ main] o.s.boot.SpringApplication : Application startup failed
118
+
119
+
120
+
121
+ org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/ApplicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/ApplicationContext.xml]
122
+
123
+ at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
124
+
125
+ at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
126
+
127
+ at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
128
+
129
+ at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
130
+
131
+ at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
132
+
133
+ at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromImportedResources(ConfigurationClassBeanDefinitionReader.java:348) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
134
+
135
+ at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:142) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
136
+
137
+ at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:116) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
138
+
139
+ at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:320) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
140
+
141
+ at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
142
+
143
+ at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:270) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
144
+
145
+ at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
146
+
147
+ at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
148
+
149
+ at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
150
+
151
+ at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) ~[spring-boot-1.5.4.RELEASE.jar:1.5.4.RELEASE]
152
+
153
+ at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) ~[spring-boot-1.5.4.RELEASE.jar:1.5.4.RELEASE]
154
+
155
+ at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-1.5.4.RELEASE.jar:1.5.4.RELEASE]
156
+
157
+ at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120) [spring-boot-test-1.5.4.RELEASE.jar:1.5.4.RELEASE]
158
+
159
+ at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
160
+
161
+ at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
162
+
163
+ at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
164
+
165
+ at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:189) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
166
+
167
+ at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:131) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
168
+
169
+ at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
170
+
171
+ at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
172
+
173
+ at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
174
+
175
+ at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.12.jar:4.12]
176
+
177
+ at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
178
+
179
+ at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
180
+
181
+ at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94) [spring-test-4.3.9.RELEASE.jar:4.3.9.RELEASE]
182
+
183
+ at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) [junit-4.12.jar:4.12]