Azure应用配置的针对用户和群组的功能标志不起作用。

huangapple go评论79阅读模式
英文:

Azure app config feature flagging for targetted users and groups not working

问题

我正在尝试将Azure应用配置与特性标志集成,并在Azure门户上为定向用户和群组添加了附加筛选器。

我正在使用以下依赖项:

implementation ('com.azure.spring:spring-cloud-azure-feature-management-web:5.2.0')

已创建了一个类似于以下的TargetingContextAccessorImpl类:

public class TargetingContextAccessorImpl implements TargetingContextAccessor {
       
    @Override
    public void configureTargetingContext(TargetingContext context) {
            context.setUserId("charu.test@gmail.com");
            ArrayList<String> groups = new ArrayList<String>();
            groups.add("abc.com");
            context.setGroups(groups);
    }
}

我还在Azure门户上创建了一个带有定向筛选器的特性标志。

我的控制器如下:

@GetMapping("/fftest")
public String test() {
    if (Boolean.TRUE.equals(featureManager.isEnabledAsync("feature-a").block())) {
        return "enabled";
    }
    return "disabled";
}

现在,在运行我的应用程序时,我遇到了以下错误:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'Microsoft.Targeting' available

我正在遵循此文档:https://learn.microsoft.com/en-us/java/api/overview/azure/spring-cloud-feature-management-readme?view=azure-java-stable

是否有人可以帮助解决上述错误日志?关于Targeting,在线上的信息相对较少。

英文:

I am trying to integrate azure app configuration with feature flagging and have added additional filter for targeted users and groups on my azure portal.

I am using below dependency:

implementation (&#39;com.azure.spring:spring-cloud-azure-feature-management-web:5.2.0&#39;)

Have created a TargetingContextAccessorImpl class like this:

public class TargetingContextAccessorImpl implements TargetingContextAccessor {
       
    @Override
    public void configureTargetingContext(TargetingContext context) {
            context.setUserId(&quot;charu.test@gmail.com&quot;);
            ArrayList&lt;String&gt; groups = new ArrayList&lt;String&gt;();
            groups.add(&quot;abc.com&quot;);
            context.setGroups(groups);
    }
}

Also i have created a feature flag with targetting filter on azure portal:

And my controller looks like:

 @GetMapping(&quot;/fftest&quot;)
    public String test() {
        if (Boolean.TRUE.equals(featureManager.isEnabledAsync(&quot;feature-a&quot;).block())) {
            return &quot;enabled&quot;;
        }
        return &quot;disabled&quot;;
    }

Now on running my application i am getting:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named &#39;Microsoft.Targeting&#39; available

I am following this document: https://learn.microsoft.com/en-us/java/api/overview/azure/spring-cloud-feature-management-readme?view=azure-java-stable

Can anyone help with the above error log. Their is v.less information available online for Targetting.

答案1

得分: 1

我通过定义另一个bean来解决了上述问题,代码如下:

@Configuration
public class TargetConfiguration {

    @Bean("Microsoft.Targeting")
    public TargetingFilter targetingFilter(TargetingContextAccessor contextAccessor) {
        return new TargetingFilter(contextAccessor, new TargetingEvaluationOptions().setIgnoreCase(true));
    }
}

这将解决您的问题。这在文档中并没有明确提到,因此需要进行一些小的验证性实验。

希望这对其他人有所帮助。

英文:

I solved the above issue by defining another bean like this:

@Configuration
public class TargetConfiguration {

        @Bean(&quot;Microsoft.Targeting&quot;)
        public TargetingFilter targetingFilter(TargetingContextAccessor contextAccessor) {
            return new TargetingFilter(contextAccessor, new TargetingEvaluationOptions().setIgnoreCase(true));
        }
    }

This will resolve your issue. This is not clearly mentioned anywhere in docs. so required lil POC.

Hope this will help some one else.

huangapple
  • 本文由 发表于 2023年6月15日 23:44:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76483371.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定