|
我写了一个webservice接口,在实现的部分调用业务层,是使用的自动注入的方式
public class SvrImplement implements SrvInterface {
private ProductService ps;
public ProductService getPs() {
return ps;
}
@Autowired
public void setPs(ProductService ps) {
this.ps = ps;
}
public List<Product> testFun(String id){
List<Product> list = null;
try{
logger.info("--------1-------webservice-----<><><><>-------------id----------="+id);
logger.info("--------1-------webservice-----<><><><>-----------------------");
list=ps.findbyid(id);
logger.info("--------2-------webservice-----<><><><>-----------------------");
}catch(Exception e){
logger.error(e);
}finally{
return list;
}
}
}
但是,被注入的类始终是null。同样的业务类,我在使用springmvc里面的controller进行自动注入,就可以初始化。这是怎么回事啊,大神们救命啊 ! |
|
![]() 15分 |
再增加一个扫描的路径 |
![]() |
我增加了<context:component-scan base-package=”com.waiqin.webservice.soap_implement” /> 这个是webservice实现类的路径,增加后还是没效果,调用service时候,仍然是null。通过springmvc的controller调用同一个service 就可以。哎。。 |
![]() 5分 |
你前面怎么调用的?
|
![]() |
我在springmvc的controller层 @Controller
public class AdminController {
private static Logger logger = Logger.getLogger(AdminController.class);
private ProductService ps;
public ProductService getPs() {
return ps;
}
@Autowired
public void setPs(ProductService ps) {
this.ps = ps;
}
@RequestMapping("/findbyid")
@ResponseBody
public List<Product> findbyid(String id) throws Exception{
List<Product> list = null;
try{
logger.info("--------1------------<><><><>-----------------------");
list=ps.findbyid(id);
logger.info("--------2------------<><><><>-----------------------");
}catch(Exception e){
logger.error(e);
}finally{
return list;
}
}
}
在controller层和webservice调用的都是同一个service |
![]() |
应该增加的是Service的路径。 |
![]() |
可以了 在web.xml和spring里面增加了一下配置,感谢大家了!
|

