Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaSpring:返回空值的服务_Java_Spring - Fatal编程技术网

JavaSpring:返回空值的服务

JavaSpring:返回空值的服务,java,spring,Java,Spring,出于某种原因,我的服务返回空值。自动连线是正确的,服务注释在那里,getter和setter。。但这将返回空值: public PlatformService getPlatformService() { return platformService; } public void setPlatformService(PlatformService platformService) { this.platformService = platformService; } 调试时

出于某种原因,我的服务返回空值。自动连线是正确的,服务注释在那里,getter和setter。。但这将返回空值:

public PlatformService getPlatformService() {
    return platformService;
}

public void setPlatformService(PlatformService platformService) {
    this.platformService = platformService;
}
调试时,它返回platformService=null

这是我的平台服务:

package empsuite.service;
    import java.util.List;
import empsuite.model.Platform;



public interface PlatformService {
    public void addPlatform(Platform platform);
    public void updatePlatform(Platform platform);
    public Platform getPlatformById(int id);
    public List<Platform> getPlatform();

}
包empsuite.service;
导入java.util.List;
导入empsuite.model.Platform;
公共接口平台服务{
公共平台(平台平台);
公共作废更新平台(平台);
公共平台getPlatformById(int-id);
公共列表getPlatform();
}
PlatformServiceImpl:

@Service
@Transactional
public class PlatformServiceImpl implements PlatformService {
    @Autowired
    PlatformDAO platformDAO;

    @Transactional(readOnly = false)
    public void addPlatform(Platform platform) {
        getPlatformDAO().addPlatform(platform);
    }
    @Transactional(readOnly = false)
    public void updatePlatform(Platform platform) {
        getPlatformDAO().updatePlatform(platform);
    }


    private PlatformDAO getPlatformDAO() {
        return platformDAO; }

    public void setPlatformDAO(PlatformDAO platformDAO) {
        this.platformDAO = platformDAO;
    }

    public Platform getPlatformById(int id) {
        return getPlatformDAO().getPlatformById(id);
    }

    public List<Platform> getPlatform() {
        return getPlatformDAO().getPlatform();
    }
}
@服务
@交易的
公共类PlatformServiceImpl实现PlatformService{
@自动连线
平台道平台道;
@事务(只读=假)
公共平台(平台平台){
getPlatformDAO().addPlatform(平台);
}
@事务(只读=假)
公共void更新平台(平台){
getPlatformDAO().updatePlatform(平台);
}
私有PlatformDAO getPlatformDAO(){
返回平台dao;}
公共无效setPlatformDAO(PlatformDAO PlatformDAO){
this.platformDAO=platformDAO;
}
公共平台getPlatformById(int id){
返回getPlatformDAO().getPlatformById(id);
}
公共列表getPlatform(){
返回getPlatformDAO().getPlatform();
}
}
DAOImpl函数(带有sessionfactory自动连线)作为HQL的构建器:

public List<Platform> getPlatform() {
    List list = getSessionFactory().getCurrentSession().createQuery("from Platform").list();
    return list;
}
public List getPlatform(){
List List=getSessionFactory().getCurrentSession().createQuery(“来自平台”).List();
退货清单;
}

@ManagedProperty是问题的原因,因此我重写了它,它与此构造函数一起工作:

public PlatformManagedBean() {
    super();
    if(platformService == null){
        WebApplicationContext ctx =  FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());
        platformService = ctx.getBean(PlatformService.class);
    }

}

@ManagedProperty是问题的原因,因此我重写了它,它与此构造函数一起工作:

public PlatformManagedBean() {
    super();
    if(platformService == null){
        WebApplicationContext ctx =  FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());
        platformService = ctx.getBean(PlatformService.class);
    }

}

胡乱猜测您在包含其getter和setter的代码中执行了
new PlatformServiceImpl
。您如何将PlatformService注入到使用它的类中?M.Deinum当然不是!Antjavadev:@ManagedProperty(value=“#{PlatformService}”)PlatformService PlatformService;列出platformListWild猜测您在包含其getter和setter的代码中正在执行
new PlatformServiceImpl
。您如何将PlatformService注入到使用它的类中?M.Deinum当然不是!Antjavadev:@ManagedProperty(value=“#{PlatformService}”)PlatformService PlatformService;列表平台列表