第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法使用具有異步 + 彈簧安全性的彈簧測試

無法使用具有異步 + 彈簧安全性的彈簧測試

元芳怎么了 2021-08-19 13:34:22
我有一個從其端點@RestController返回DeferredResult對象的類。在到達這些端點之前,我使用一個@EnableWebSecurity類來設(shè)置基本身份驗證。我能夠使用正確的基本身份驗證在本地卷曲這些端點并使其工作。但是,通過 spring 測試測試這些端點會導(dǎo)致此異常:java.lang.ClassCastException: org.springframework.security.web.servletapi.HttpServlet3RequestFactory$SecurityContextAsyncContext 不能轉(zhuǎn)換為 org.springframework.mock.web.MockAsyncCont我已經(jīng)嘗試在我的測試類上使用@WebAppConfiguration和@ContextConfiguration(classes = SpringSecurityConfig.class)注釋并設(shè)置MockMvc我自己(SpringSecurityConfig只是我實現(xiàn)基本身份驗證的類)。我也試過只使用@SpringBootTestand @AutoConfigureMockMvc。這是我當前的測試課程:@RunWith(SpringRunner.class)@WebAppConfiguration@ContextConfiguration(classes = SpringSecurityConfig.class)public class PushNotificationControllerSpringTest {    @MockBean    BucketDetailsService bucketDetailsService;    @MockBean    NotificationService notificationService;    @Autowired    protected WebApplicationContext wac;    private MockMvc mockMvc;    @Before    public void prepare() {        mockMvc = MockMvcBuilders.webAppContextSetup(wac).apply(springSecurity()).build();    }    @Test    public void testListBulletins() throws Exception {        mockMvc.perform(asyncDispatch(                mockMvc.perform(get("/admin/bulletins").header("Authorization", "Basic YWRtaW46cGFzc3cwcmQ="))                        .andExpect(status().isOk()).andReturn()));    }}這是我的休息控制器:@RestController@RequestMapping("/admin")public class PushNotificationController {    protected static final Logger logger = LoggerFactory.getLogger(PushNotificationController.class);    @Autowired    BucketDetailsService bucketDetailsService;    @GetMapping("/bulletins")    public DeferredResult<List<BulletinDetails>> listBulletins() {        DeferredResult<List<BulletinDetails>> deferredResult = new DeferredResult<>();        logger.debug("Fetching bulletins...");        bucketDetailsService.listBulletins()                .whenComplete((res, ex) -> setResult(deferredResult, res, ex, "List bulletins"));        return deferredResult;    }
查看完整描述

2 回答

?
米脂

TA貢獻1836條經(jīng)驗 獲得超3個贊

這是 Core Spring 中已修復(fù)的錯誤。

有關(guān)詳細信息,請參閱SPR-16695。

如果升級到 Spring Framework 4.3.16、5.0.6 或更高版本,問題應(yīng)該會消失。

如果升級后它沒有消失,請創(chuàng)建一個新的JIRA 問題來描述問題。


查看完整回答
反對 回復(fù) 2021-08-19
?
胡子哥哥

TA貢獻1825條經(jīng)驗 獲得超6個贊

更新你的測試


 @Test

 public void PushNotificationControllerSpringTest() throws Exception {


 ....


 MvcResult mvcResult = this.mockMvc.perform(get("/admin/bulletins").header("Authorization", "Basic YWRtaW46cGFzc3cwcmQ="))

    .andExpect(request().asyncStarted()).andReturn();


     this.mockMvc.perform(asyncDispatch(mvcResult)).andExpect(status().isOk());

 }

}


查看完整回答
反對 回復(fù) 2021-08-19
  • 2 回答
  • 0 關(guān)注
  • 207 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號