@Service上的Spring @Conditional导致NullPointer问题

时间:2018-12-17 11:10:08

标签: spring conditional

当我运行该应用程序时,java.lang.NullPointerException使其停止。

@Conditional可以在@Service或@Component上使用吗?

我的代码在这里:

public interface PersonService {
    void doSomething();
}

@Conditional(MaleCondition.class)
@Service
public class MaleService implements PersonService {
    @Override
    public void doSomething() {
        System.out.println("I'm male!");
    }
}

@Conditional(FemaleCondition.class)
@Service
public class FemaleService implements PersonService {
    @Override
    public void doSomething() {
        System.out.println("I'm female!");
    }
}

0 个答案:

没有答案