启动Spring Boot 出错:Failed to bind properties under ‘emp’ to com.njust.platform_server.service.Emp

Description:

Failed to bind properties under 'emp' to com.njust.platform_server.service.Emp$$EnhancerBySpringCGLIB$$6ee3bc26:

    Reason: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'emp' to com.njust.platform_server.service.Emp$$EnhancerBySpringCGLIB$$6ee3bc26

Action:

Update your application's configuration

新手很常见的问题,有各种原因,我这里是因为在实体类里写了方法,导致不匹配

@Configuration
@ConfigurationProperties(prefix = "emp")
//@PropertySource(value = "classpath:hadoop.yml")
@Data
public class Emp {
    private int port;
    private String type;


    public void getParameters(){
        System.out.println(port);
        System.out.println(type);
    }
}

删掉就好了,这个类里不允许有任何其它方法

@Configuration
@ConfigurationProperties(prefix = "emp")
//@PropertySource(value = "classpath:hadoop.yml")
@Data
public class Emp {
    private int port;
    private String type;
    
}

太蠢了。。。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐