方法:
在类中创建一个静态的bean对象,然后使用init方式初始化这个bean,这样就可以在静态方法中调用了
@Service("idg")
public class IDGenerator {
@Autowired
private IIDGeneratorDAO dao;
private static IDGenerator generator;
public void setDao(IIDGeneratorDAO dao) {
this.dao = dao;
}
@PostConstruct
public void init() {
generator = this;
generator.dao = this.dao;
}
@Transactional
public static String getId() {
return generator.dao.getId();
}
@Transactional
public static String getId(String name) {
return generator.dao.getId(name);
}
}