通过执行以下示例,我正在学习如何将 Spring 与 GWT 和 RequestFactory 集成。我得到一个 NullPointerException ,我不知道为什么。谁能帮我?
这是我的代码:
@Repository
public class EmployeeDAO implements IEmployeeDAO {
@PersistenceContext
private EntityManager entity;
@Override
public Employee findById(Long id) {
Query query = entity.createQuery("from Employee where id = :param");
query.setParameter("param", id);
query.setMaxResults(1);
return (Employee) query.getSingleResult();
}
@Transactional(propagation = Propagation.REQUIRED)
@Override
public void save(Employee employee) {
entity.merge(employee);
}
@Override
public void remove(Employee employee) {
entity.remove(employee);
}
@SuppressWarnings("unchecked")
@Override
public List<Employee> getAllEmployee() {
Query query = entity.createQuery("from Employee");
return query.getResultList();
}
// ...
}
和:
@Service(value = IEmployeeDAO.class, locator = DaoLocator.class)
public interface EmployeeRequestContext extends RequestContext {
Request<EmployeeProxy> findById(Long id);
Request<Void> save(EmployeeProxy employee);
Request<Void> remove(EmployeeProxy employee);
Request<List<EmployeeProxy>> getAllEmployee();
Request<EmployeeProxy> findOneByName(String name);
}
和:
@ProxyFor(Employee.class)
public interface EmployeeProxy extends EntityProxy {
Long getId();
String getName();
String getSurname();
void setId(Long id);
void setName(String name);
void setSurname(String surname);
Long getVersion();
void setVersion(Long version);
}
NullPointerException 在方法中被抛出 GWT 入口点:
protected void refresh() {
context = createFactory().employeeRequest();
final EmployeeProxy ep = context.create(EmployeeProxy.class);
ep.setName("Jan");
ep.setSurname("Kowalski");
ep.setVersion(new Long(0));
context.save(ep).fire(new Receiver<Void>() {
@Override
public void onSuccess(Void response) {
employeeList.add(ep);
}
@Override
public void onFailure(ServerFailure error) {
System.out.println("error podczas zapisu");
}
});
context = createFactory().employeeRequest();
context.getAllEmployee().fire(new Receiver<List<EmployeeProxy>>() {
@Override
public void onSuccess(List<EmployeeProxy> response) {
System.out.println(" " + response); // NULL
}
@Override
public void onFailure(ServerFailure error) {
}
});
System.out.println("Bedziemy wyswietlac dane!");
updateTable(employeeList);
}
最后一个:创建工厂的方法:
private static EmployeeRequestFactory createFactory() {
EmployeeRequestFactory factory = GWT.create(EmployeeRequestFactory.class);
factory.initialize(new SimpleEventBus());
return factory;
}
请帮我...