【问题标题】:No qualifying bean of type 'org.springframework.cloud.bootstrap.encrypt.RsaProperties'没有“org.springframework.cloud.bootstrap.encrypt.RsaProperties”类型的合格bean
【发布时间】:2019-01-21 17:04:29
【问题描述】:

正如标题所示,我得到了一个 nosuchbean 异常,只是在此处添加文本以满足大部分代码的需求。

在 jre\lib\security 中放置了无限的加密罐

在 src\main\resources 的应用程序中创建的密钥库,名为 config-server.jks

application.properties(尝试了两个 key-stores 位置属性定义)

server.port=8888
spring.cloud.config.server.git.uri=ssh://git@v00bitbucket:7999/proj/config-server.git
spring.cloud.config.server.git.clone-on-start=true
security.user.name=Joe
security.user.password={bcrypt}$2a$10$7H8tnjyf/Mn90eAZADruterXJ.t.GQP4WgRIZ8cwnRsMmhZhCtS1a
#encrypt.key-store.location=classpath:/config-server.jks
encrypt.key-store.location=file://C:/myAppDir/config- server/src/main/resources/config-server.jks
encrypt.key-store.password=my-s70r3-s3cr3t
encrypt.key-store.alias=config-server-key
encrypt.key-store.secret=my-k34-s3cr3t

使用 java 1.8.0_77

@RunWith(SpringRunner.class)
@SpringBootTest
public class ConfigServerApplicationTests {    
    @Test
    public void contextLoads() {
    }
}    


@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
    }
}

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
    @Value("${security.user.name}")
    private String authUser;
    @Value("${security.user.password}")
    private String authPassword; // this password is encoded
    @Autowired
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication().passwordEncoder(PasswordEncoderFactories.createDelegatingPasswordEncoder())
        .withUser(authUser).password(authPassword).roles("User");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().fullyAuthenticated();
        http.httpBasic();
        http.csrf().disable();
    }
}

这里是 pom {

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.4.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <spring-cloud.version>Finchley.SR1</spring-cloud.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-rsa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

}

【问题讨论】:

  • 这里是 keytool 命令: keytool -genkeypair -alias config-server-key -keyalg RSA -keysize 4096 -sigalg SHA512withRSA -dname "CN=Config Server,OU=Spring,O=MyOrg" - keypass my-k34-s3cr3t -keystore config-server.jks -storepass my-s70r3-s3cr3t
  • 堆栈跟踪是什么?
  • 不知道如何添加堆栈跟踪,因为注释中的字符有限
  • @user1346730 你应该编辑帖子以添加堆栈跟踪。
  • 只是一个简单的问题。我看到密钥库位置在“config-server”中有一个空格,对吗?此外,错误堆栈跟踪将有很大帮助...

标签: java spring spring-boot spring-security


【解决方案1】:

也遇到了这个问题。

我最好的猜测是它是最新版本的 Spring Cloud 中的一个错误。我将在 Spring Cloud 项目上打开一个问题,并在完成后将其链接到此处。

我使用的是 application.yml,而不是 application.properties。

当你在应用程序 yml 中放置任何 encrypt: * 配置时,它会给你这个错误。作为一项工作,我尝试将 encrypt:* 配置放入 bootstrap.yml

之后,Spring Boot 应用程序启动成功,它将拥有 RsaProperties Bean :)

希望这会有所帮助!

【讨论】:

  • Link 在 Github 上打开问题。
猜你喜欢
  • 2018-07-12
  • 1970-01-01
  • 1970-01-01
  • 2022-01-14
  • 2019-04-27
  • 2020-06-18
  • 2020-06-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多