[英]SpringApplicationConfiguration can't be resolved to a type
I know this question has been posted before, but I couldn't resolve it from that post.我知道这个问题之前已经发布过,但我无法从那个帖子中解决它。 I get the error that "SpringApplicationConfiguration cannot be resolved to a type" in the following code:
我在以下代码中收到“无法将 SpringApplicationConfiguration 解析为类型”的错误:
package com.caveofprogramming.tests;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import com.caveofprogramming.App;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(App.class)
@WebAppConfiguration
public class StatusTest {
@Test
public void testDummy() {
long value = 7l;
assertNotNull("Value should not be null", value);
}
}
This has the following dependency in the pom.xml file:这在 pom.xml 文件中具有以下依赖关系:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.1.9.RELEASE</version><!--$NO-MVN-MAN-VER$-->
</dependency>
What can I do to get rid of this error but not cause any other issues?我能做些什么来摆脱这个错误但不会导致任何其他问题? Thanks.
谢谢。
Here below is App.java: package com.caveofprogramming;下面是 App.java: package com.caveofprogramming
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.view.UrlBasedViewResolver;
import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
import org.springframework.web.servlet.view.tiles3.TilesView;
@SpringBootApplication
public class App extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder
application) {
return application.sources(App.class);
}
@Bean
public TilesConfigurer tilesConfigurer() {
TilesConfigurer tilesConfigurer = new TilesConfigurer();
String[] defs = {"/WEB-INF/tiles.xml"};
tilesConfigurer.setDefinitions(defs);
return tilesConfigurer;
}
@Bean
public UrlBasedViewResolver tilesViewResolver() {
UrlBasedViewResolver tilesViewResolver = new UrlBasedViewResolver();
tilesViewResolver.setViewClass(TilesView.class);
return tilesViewResolver;
}
}
I believe a configuration like this will get you going我相信这样的配置会让你继续前进
@RunWith(SpringRunner.class)
@ComponentScan(basePackages = {"com.caveofprogramming"})
@SpringBootTest
@AutoConfigureMockMvc
I assume there's a lot more to your test (or there intends to be) than what you've listed.我认为您的测试(或打算)比您列出的要多得多。 If you're truly going to just make a simple test like this, run with the Mockito runner, and you don't need the rest of that nonsense.
如果你真的要做这样一个简单的测试,用 Mockito 跑步者运行,你不需要那种废话的 rest。
@RunWith(MockitoJUnitRunner.class)
Note that this assumes you're attempting to perform a test of your controllers, based on the fact that you have annotated your test with @WebAppConfiguration
请注意,这假设您正在尝试执行控制器测试,基于您已使用
@WebAppConfiguration
注释测试的事实
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.