前几天,在sf这里也提过这个问题,但是仍未得到解决,上一个问题是这个在Service中注入Dao不成功,Dao为null。但根据大虾们的回答,我想再理顺一下这个项目的逻辑,免得各位看着都不懂我在说什么。本人是spring小白,整个项目环境搭建是前辈写下的,我只是根据他的方法来添加修改,所以有很多框架上的逻辑我并不是看得很懂。
我想实现的是——用多线程通过socket不断获取从客户端发送过来的消息,并对消息联系JDBC进行分析。
P.S.代码部分都只截取了重要的部分
我先放一下其中一个service和dao的实现:
1)ConcentratorService:
public interface ConcentratorService {
public List getConcentratorListByMacAddresses(String[] macAddr) throws Exception;
}
2)ConcentratorServiceImpl:
@Service("ConcentratorService")
public class ConcentratorServiceImpl implements ConcentratorService{
@Autowired
ConcentratorDao concentratorDao;
public Concentrator findConcentratorByCaddress(String caddress) throws Exception{
// TODO Auto-generated method stub
return concentratorDao.findConcentratorByCaddress(caddress);
}
}
3)ConcentratorDao
public interface ConcentratorDao {
public List getConcentratorListByMacAddresses(String[] macAddr) throws Exception;
}
4)ConcentratorDaoImpl
public class ConcentratorDaoImpl implements ConcentratorDao {
@Autowired
SessionFactory sessionFactory;
Session session = null;
Transaction tx = null;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory=sessionFactory;
}
@Override
public List getConcentratorListByMacAddresses(String[] macAddr) throws Exception {
session = sessionFactory.openSession();
tx = session.beginTransaction();
StringBuffer sb = new StringBuffer("from Concentrator where caddress in (");
for(int i=0; i
if(i==macAddr.length-1){
sb.append("?)");
}else{
sb.append("?,")