ssh框架中,工具类调用service层方法(参考https://www.cnblogs.com/l412382979/p/8526945.html)

时间:2024-12-17 12:07:02

代码如下:

package common.dataService;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import com.womow.uap.bizc.IUapusersBizc;
import com.womow.vo.DBVo; @Component//声明spring组件
public class DBTool {
@Autowired
private IUapusersBizc uapusersBizc; public static DBTool instance ; public void setUapusersBizc(IUapusersBizc uapusersBizc) {
this.uapusersBizc = uapusersBizc;
} @PostConstruct//通过@PostConstruct方法实现Bean初始化之前和销毁之前的自定义操作
public void init(){//init方法是在构造函数执行之后 才执行的
instance = this;
instance.uapusersBizc = this.uapusersBizc;
} public DBVo getDBVoInfo(){
DBVo dbVo = null;
try {
dbVo = uapusersBizc.findDBInfo();
} catch (Exception e) {
e.printStackTrace();
}
return dbVo;
}
}