我有一个主要类的spring boot应用程序,如下所示:
@SpringBootApplication
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想测试我的服务并创建一个基础测试类:
@SpringApplicationConfiguration(Application.class)
public abstract class TestBase {
}
Run Code Online (Sandbox Code Playgroud)
当我运行我的测试时,我得到例外:
Caused by: java.lang.IllegalArgumentException: Can not load an ApplicationContext with a NULL 'contextLoader'. Consider annotating your test class with @ContextConfiguration.
at org.springframework.util.Assert.notNull(Assert.java:115)
at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:117)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
Run Code Online (Sandbox Code Playgroud)
然后我使用ContextConfiguration更改我的基本测试类
@ContextConfiguration(classes = Application.class)
public abstract class TestBase {
}
Run Code Online (Sandbox Code Playgroud)
这次我得到DataSource初始化错误.我想知道为什么它在第一种情况下失败,为什么在第二种情况下它不加载我已经配置数据源的application.properties.
谢谢!
假设我的微服务架构中有一个 UserService部署在云上。有一个服务发现用于将请求路由到不同的 UserService 主机。
如果我有两个不同版本的 UserService。假设user-service-1.0和user-service-2.0以及部分客户端仍应使用旧版本,那么如何在微服务架构中对其进行管理。