首页 > 解决方案 > 需要一个找不到的“de.codecentric.boot.admin.server.config.AdminServerProperties”类型的 bean

问题描述

我有这个问题

需要一个找不到的“de.codecentric.boot.admin.server.config.AdminServerProperties”类型的 bean

考虑在配置中定义“de.codecentric.boot.admin.server.config.AdminServerProperties”类型的 bean。

这是我的 POM

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

    <!--Add login page and logout feature -->
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-starter-server</artifactId>
        <version>2.2.2</version>
    </dependency>
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-server</artifactId>
        <version>2.2.2</version>
    </dependency>
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-server-ui</artifactId>
        <version>2.2.2</version>
    </dependency>
    <!--Add login page and logout feature -->
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-server-ui-login</artifactId>
        <version>1.5.7</version>
    </dependency>
    <dependency>
        <groupId>com.hazelcast</groupId>
        <artifactId>hazelcast</artifactId>
    </dependency>
    <!--declare the admin server as a client, for self monitoring -->
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-starter-client</artifactId>
        <version>2.2.2</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
</dependencies>

知道是什么原因吗?

公共类 WebSecurityConfig 扩展 WebSecurityConfigurerAdapter {

private final AdminServerProperties adminServer;

public WebSecurityConfig(AdminServerProperties adminServer) {
    this.adminServer = adminServer;
}

标签: javaspringspring-boot

解决方案


在主类(@SpringBootApplication)上方添加@Import(AdminServerProperties.class)就足够了


推荐阅读