Java 使用策略设计模式和@Autowired将Bean实例获取为null

Java 使用策略设计模式和@Autowired将Bean实例获取为null,java,inversion-of-control,autowired,strategy-pattern,Java,Inversion Of Control,Autowired,Strategy Pattern,嗨,我正在尝试使用策略设计模式。我在TestServiceImpl类中将ReencryptionOperationbean设置为null 这是我的界面 public interface ReEncryptionOperation { void performOperation (String name); } 这些是我的实现类 public class Test1 implements ReEncryptionOperation { @Override public void p

嗨,我正在尝试使用策略设计模式。我在TestServiceImpl类中将ReencryptionOperationbean设置为null

这是我的界面

public interface ReEncryptionOperation {

    void performOperation (String name);
}
这些是我的实现类

public class Test1 implements ReEncryptionOperation {


@Override
public void performOperation(String name){

    return ....;
   }
}


public class Test2 implements ReEncryptionOperation {


@Override
public void performOperation(String name) {

    return ....;
}
}
这是我定义为bean的配置类

  @Configuration
  @Slf4j
  public class TestConfiguration
  {
   @Bean("reEncryptionOperation")
  public ReEncryptionOperation getReEncryptionOperation () throws ReEncryptionException {

    if (annotationSupport) {
        return new Test1();
    }
    return new Test2();
}

 }
这是我的服务类,我正在尝试使用@Autowired重新加密操作。但是我正在变空

 @Component
@Slf4j
 public class TestServiceImpl
 {

@Autowired
private ReEncryptionOperation reEncryptionOperation;



public ReEncryptionResponse submitJob (
    final ReEncryptionRequest reEncryptionRequest) throws ReEncryptionException
{
        reEncryptionOperation.performOperation(test);
        
}

}

您的配置似乎正常。 检查
TestConfiguration
是否位于spring扫描的包中

为了确保bean是在运行时创建的,请在方法
getReEncryptionOperation