如何创建AADAuthenticationProperties的bean(天蓝色)?

时间:2019-08-06 06:54:09

标签: azure spring-boot dependency-injection azure-active-directory spring-boot-starter

我无法创建AADAuthenticationProperties的bean,原因是属性activeDirectoryGroups不能为空。

错误如下:

绑定到目标org.springframework.boot.context.properties.bind.BindException:无法将“ azure.activedirectory”下的属性绑定到com.microsoft.azure.spring.autoconfigure.aad.AADAuthenticationProperties失败:

Property: azure.activedirectory.activeDirectoryGroups
Value: null
Reason: no puede estar vacío

这是尝试的两种方法:

    //1st option
    @Bean
    @ConditionalOnMissingBean
    public AADAuthenticationProperties aadAuthenticationPropertiesFactory() {
        return new AADAuthenticationProperties();
    }

    //2nd option
    @Bean
    @ConditionalOnMissingBean
    public AADAuthenticationProperties aadAuthenticationPropertiesFactory() {
        AADAuthenticationProperties aadAuthenticationProperties = new AADAuthenticationProperties();
        aadAuthenticationProperties.setactiveDirectoryGroups(new ArrayList<>());
        return aadAuthenticationProperties;
}

但是错误仍然存​​在,所以关于什么是activeDirectoryGroups属性以及如何创建AADAuthenticationProperties Bean的任何想法?我正在使用Java 8。

非常感谢您!

1 个答案:

答案 0 :(得分:1)

就像@ M.Deinum在评论中说的那样,您只需要在application.properties中指定属性。 Bean将通过Azure自动配置生成。有关更多详细信息,请参阅此document

azure.activedirectory.active-directory-groups=group1, group2