我有两个弹簧启动应用程序.
我在application.properties文件中使用此属性设置了端口
server.port=${port:9090}
Run Code Online (Sandbox Code Playgroud)
两个模块都有/ login,/ signup,无需通过以下代码完成身份验证即可访问.
http.authorizeRequests()
.antMatchers("/signup", "/login").permitAll()
Run Code Online (Sandbox Code Playgroud)
任何其他请求都要求对用户进行身份验证.
如果我一次使用一个模块没有问题,
但是如果尝试在同一时间来回使用它们,那么问题是我每次使用另一个时都必须再次登录到之前的应用程序.例如.
我很确定这是因为模块2重置了jessionid.
HTTP cookie端口是否特定? 我已经阅读了这篇文章,其中指出cookie不是特定于端口的.
但必须有一个解决方案,这样我每次切换应用程序时都不必登录.
我想使用 @WebMvcTest 注释测试依赖于 1 个服务和 1 个存储库的单个控制器。整个应用程序中还有其他 5 个服务/存储库,我不想在这个单元测试中模拟它们。
我已经嘲笑了所需的 2 个服务/存储库。在这里,我正在测试一个简单的端点,它甚至不访问存储库,但是当我尝试在 Spring Boot 中对该特定控制器进行单元测试时,如下所示
@RunWith(SpringRunner.class)
@WebMvcTest(WebController.class)
public class LoginTest {
@MockBean
private CustomerRepository customerRepository;
@MockBean
private CustomerService customerService;
private MockMvc mockMvc;
@Test
public void serverRunning() throws Exception {
this.mockMvc.perform(get("/"))
.andExpect(status().isOk())
.andExpect(content().string("Server is running"))
.andDo(print());
}
}
Run Code Online (Sandbox Code Playgroud)
我明白了
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restaurantRequestRepository': Cannot create inner bean '(inner bean)#60b4d934' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name …