当我运行该应用程序时,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!");
}
}