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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Spring @Configuration 未在測(cè)試上下文中覆蓋

Spring @Configuration 未在測(cè)試上下文中覆蓋

白板的微信 2022-03-10 22:09:13
今天我將我的項(xiàng)目從 Spring Boot 1.5.9 更新到 2.1.1,我的一些測(cè)試停止工作。當(dāng)我開始測(cè)試時(shí),控制臺(tái)上會(huì)彈出錯(cuò)誤:com.example.rest.config.SecurityConfig 中的字段 authEntryPoint 需要找不到類型為“com.example.rest.service.auth.entrypoints.AuthenticationEntryPoint”的 bean。問題是我在我的 SecurityConfig 類中定義了這種類型的 bean,但是我在 TestApplication 類的測(cè)試包中覆蓋了這個(gè)配置。安全配置在那里定義為靜態(tài)內(nèi)部類。我嘗試了不同的方法,包括 Spring 配置文件和 @Primary 注釋,但似乎沒有任何效果,而且 Spring 沒有像以前那樣選擇我的測(cè)試配置。只有當(dāng)我刪除了 SecurityConfig 類的非測(cè)試版本并且測(cè)試版本變成了這種類型的唯一 bean 時(shí)才起作用。有人可以告訴我如何覆蓋這個(gè)原始配置或如何關(guān)閉 Spring Security 以進(jìn)行測(cè)試嗎?或者也許有一種方法可以強(qiáng)制 Spring 不選擇那個(gè)非測(cè)試 @Configuration bean?安全配置類    @Configuration    @EnableWebSecurity    public class SecurityConfig extends WebSecurityConfigurerAdapter {        @Autowired        AuthenticationEntryPoint authEntryPoint;        @Autowired        BasicAuthenticationProvider basicAuthProvider;        @Autowired        PreAuthenticatedUserDetailsService preAuthUserDetailsService;        @Override        protected void configure(HttpSecurity http) throws Exception {            http                .authorizeRequests()                    .antMatchers("/rest/query/id/*/user/*",                            "/rest/files/**/*").hasAnyRole("CLIENT", "SYSTEM")                    .antMatchers("/public/api/management/**/*").hasRole("SYSTEM")                    .antMatchers("/public/api/**/*").hasAnyRole("SYSTEM", "USER")                    .antMatchers("/rest/**/*").hasRole("SYSTEM")                    .and()                .x509()                    .userDetailsService(preAuthUserDetailsService)                    .and()                .httpBasic()                    .authenticationEntryPoint(authEntryPoint)                    .and()                .sessionManagement()                    .sessionCreationPolicy(SessionCreationPolicy.STATELESS)                    .and().csrf().disable();        }        @Autowired        public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {                   auth.authenticationProvider(basicAuthProvider);             }
查看完整描述

1 回答

?
千萬里不及你

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超9個(gè)贊

我設(shè)法使用@Profileand來完成這項(xiàng)工作@ActiveProfiles。但是我不得不將我的靜態(tài)內(nèi)部@Configuration類提取到另一個(gè) java 文件中,然后它自動(dòng)開始工作。仍然沒有找到為什么它在早期版本的 Spring Boot 中工作


查看完整回答
反對(duì) 回復(fù) 2022-03-10
  • 1 回答
  • 0 關(guān)注
  • 191 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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