我在单独的弹簧启动模块中具有控制器,服务和DAO。我尝试使用JPA API StoredProcedureQuery方法从DAO模块调用存储过程,因为这需要自动装配EntityManager。如果我将DAO作为弹簧启动应用程序单独运行,则此设置有效。但是当我从控制器调用此DAO类时,我得到了NullPointerException。
我在DAO项目中的LoginDAO
@Repository
public class LoginDAO implements ILoginDAO {
@Autowired
EntityManager entityManager;
@Transactional
public LoginEntity getLoginCheck(String[] loginfo) {
StoredProcedureQuery storedProcedure =entityManager.createStoredProcedureQuery("DPR_LOGIN_CHECK");
}
}
我在Controller Module中的LoginController类
@Controller
public class LoginController {
@Autowired
LoginDAO loginDAO;
@RequestMapping(value = "/LoginAction", method = RequestMethod.POST)
public @ResponseBody
String getLoginCheck(@RequestParam(value = "dataString") String dataString,
HttpSession session, HttpServletRequest request,
HttpServletResponse response) {
loginDAO.getLoginCheck(null,loginDetails);
}
}
我的控制器项目依赖于DAO。这是我的主控制器类
@SpringBootApplication(scanBasePackages={"com.mars.presentation","com.mars.UserManagementControllers","com.mars","com.mars.CommonDAO"})
public class MarsApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MarsApplication.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(MarsApplication.class, args);
}
}
和主要的DAO类
@SpringBootApplication(scanBasePackages={"com.mars.CommonDAO"})
@EntityScan(basePackages={"com.mars.CommonEntities"})
@EnableJpaRepositories
public class CommonDao {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(CommonDao.class, args);
String[] loginfo = new String[] {"cjva", "Banaacvdvna", "Orange", "Grapes"};
LoginDAO loginDAO = ctx.getBean(LoginDAO.class);
loginDAO.getLoginCheck(null,loginfo);
}
}