我用:
一切都配置了Java Config(包括spring-security)
我正在开发一个Web服务器项目,其中Authentication:Basic base64Gibberish header用于验证用户身份.
问题是取决于URI AuthenticationManager是不同的(因为我需要2个不同的UserDetailsService.
我试过的多个扩展名WebSecurityConfigurerAdapter与
@Override
@Bean( name = "authManager1" )
public AuthenticationManager authenticationManagerBean() throws Exception
Run Code Online (Sandbox Code Playgroud)
@Override
@Bean( name = "authManager2" )
public AuthenticationManager authenticationManagerBean() throws Exception
Run Code Online (Sandbox Code Playgroud)
无济于事
我总是得到:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain'
defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Instantiation of bean failed;
nested exception is org.springframework.beans.factory.BeanDefinitionStoreException:
Factory method [public javax.servlet.Filter org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain() throws java.lang.Exception]
threw exception; nested exception is …Run Code Online (Sandbox Code Playgroud) 我有一个配置属性实例,前缀为"assets".
@Configuration
@ConfigurationProperties( prefix = "assets", ignoreUnknownFields = true )
public class AssetsProperties
{
@NotNull
private Resource file;
public Resource getFile()
{
return file;
}
public void setFile( Resource file )
{
this.file = file;
}
}
Run Code Online (Sandbox Code Playgroud)
其默认配置定义如下:
@Configuration
@PropertySource( name = "assetsConfig", value = "classpath:com/package/boot/web/ui/assets/config/default-assets-config.properties" )
@Order( LOW_ORDER )
public class AssetsConfig
{
}
Run Code Online (Sandbox Code Playgroud)
default-assets-config.properties包含:
assets.file=classpath:assets.json
Run Code Online (Sandbox Code Playgroud)
在我的单元测试中,我想使用以下方法覆盖默认值:
@TestPropertySource( locations = "classpath:com/package/boot/web/ui/assets/tests/assets-config.properties" )
Run Code Online (Sandbox Code Playgroud)
assets-config.properties包含
assets.file=classpath:com/package/boot/web/ui/assets/tests/assets.json
Run Code Online (Sandbox Code Playgroud)
不幸的是,这个值永远不会注入AssetsProperties.我做错了什么,我不明白,因为Spring fmk ref doc说
测试属性源的优先级高于从操作系统环境或Java系统属性加载的属性源,以及应用程序通过@PropertySource或以编程方式声明性地添加的属性源.
提前致谢,
Paskos