小编use*_*132的帖子

在同时使用两个弹簧启动应用程序时退出一个弹簧应用程序

我有两个弹簧启动应用程序.

  • module1在端口8080上运行
  • module2在端口9090上运行

我在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)

任何其他请求都要求对用户进行身份验证.

如果我一次使用一个模块没有问题,

但是如果尝试在同一时间来回使用它们,那么问题是我每次使用另一个时都必须再次登录到之前的应用程序.例如.

  1. 转到登录页面到module1 - (标题响应已设置jsessionid = XX)确定
  2. 登录module1 - 确定
  3. 浏览module1上的安全内容 - 确定
  4. 在模块2上转到注册页面 - (标题响应已设置jsessionid = YY)确定
  5. 尝试浏览module1上的另一个安全内容 - 我必须再次登录

我很确定这是因为模块2重置了jessionid.

HTTP cookie端口是否特定? 我已经阅读了这篇文章,其中指出cookie不是特定于端口的.

但必须有一个解决方案,这样我每次切换应用程序时都不必登录.

cookies port spring-security jsessionid spring-boot

2
推荐指数
1
解决办法
887
查看次数

为什么单元测试尝试在 Spring Boot 中的控制器特定单元测试中查找其他 bean

我想使用 @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 …

unit-testing mocking spring-mvc spring-boot

2
推荐指数
1
解决办法
1019
查看次数