所以我有这个Model / Repository / Service设置,我试图保存一个对象。一切正常,直到我尝试保存文档。每当我尝试保存它时,我都会得到这个堆栈跟踪...
java.lang.NullPointerException
at **.pricing.account.service.impl.BcpDocumentServiceImpl.save(BcpDocumentServiceImpl.java:62)
at **.pricing.tool.impl.SowServiceImpl.createBACPSOW(SowServiceImpl.java:81)
at **.pricing.account.web.BCPController.bcpSubmit(BCPController.java:69)
我在config.xml文件中定义了存储库...
<jpa:repositories base-package="com.spohnconsulting.pricing.account.repository"/>
这里是/ Repository / Service本身的代码
存储库:
package com.spohnconsulting.pricing.account.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface BcpDocumentRepository extends JpaRepository<BcpDocument, Long> {
}
服务接口:
/**
*
* @author willkara
*/
public interface BcpDocumentService {
void save(BCP bcp,String dest);
}
服务本身:
@Service
public class BcpDocumentServiceImpl implements BcpDocumentService {
@Autowired
private BcpDocumentRepository bcpDocumentRepository;
@Override
public void save(BCP bcp, String dest) {
BcpDocument bcpDoc = new BcpDocument();
bcpDoc.setDocumentCreationDate(new Date().toString());
bcpDoc.setDocumentName("TESTING");
try {
bcpDoc.setDocumentData(Files.readAllBytes(new File(dest).toPath()));
} catch (IOException ex) {
Logger.getLogger(BcpDocumentServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
bcpDocumentRepository.save(bcpDoc);
}
}
但是每次我运行它,我仍然会得到一个NullPointerException。我的猜测是,它不能通过Spring正确初始化。我唯一担心的是我为登录机制(用户/角色)做了同样的实现