假设我有课。
@Service
public class SomeService {
private String name;
public void setName(String name) {
this.name = name;
}
public void printHello() {
System.out.println("Spring 3 : Hello ! " + name);
}
}
默认情况下会为此 bean 创建 someService bean id。我想将这个 bean id 更改为“abc”。我该怎么做?
最佳答案
@Service("abc") 会达到你想要的效果。
这将适用于任何@Component注释,例如@Service、@Repository和@Controller等。
关于spring - 通过spring注解的方式给出bean id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39900148/