spring – 奇怪的异常:“名称不能为null或为空!”

spring – 奇怪的异常:“名称不能为null或为空!”
我在 Spring项目中遇到一个奇怪的错误,如下所示:

SEVERE: Servlet.service() for servlet [calzoneServlet] in context with path [/calzone] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Name must not be null or empty!; nested exception is java.lang.IllegalArgumentException: Name must not be null or empty!] with root cause
java.lang.IllegalArgumentException: Name must not be null or empty!

在这个项目中,所有模型都使用hibernate和jpa映射到数据库.前端使用Twitter Bootstrap(带弹簧形式验证等)

错误发生在程序的不同部分,其中一个是激活用户帐户的控制器(下面的代码).对我来说,这看起来像某种验证错误,但它不是我曾经定义的错误.由于我无法确定错误的确切位置,因此我将仅提供下面的控制器.值得注意的是,activateUser方法中的任何调试消息(无论是通过记录器还是仅仅是一个普通的旧sysout)都不会显示.

所有依赖项(pom.xml)都可以在这里找到:http://pastebin.com/fs7SG0W2
Web.xml:http://pastebin.com/vAJh29Aw
整个堆栈跟踪可以在这里找到:http://codepad.org/p0Yt5hi2(在键盘上,因为它有水平滚动)

有没有人知道为什么会发生这种错误,或者有任何线索可以找出为什么会发生这种错误?

@Controllerpublic class ActivateAccountController {    final Logger logger = LoggerFactory.getLogger(getClass());    @RequestMapping(value = "/activate/{keyString}", method = RequestMethod.GET)    public String activateUser(@PathVariable String keyString) {        ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");        KeyService keyService = (KeyService) context.getBean("keyService");        UserService userService = (UserService) context.getBean("userService");        User user;        try {            logger.error("DID I GET HERE?");            user = keyService.findUserByKey(keyString);        } catch (KeyNotFoundException ex) {            return "ActivatedNotAccount";        } finally {            // Close the application context in every case            context.close();        }        // Activate the in-memory user        userService.activateUser(user);        // Delete the key from the database        keyService.deleteKey(keyString);        // Finally, update the user in the database        userService.updateUser(user);        logger.info("Acticated user with ID "{}", First name: "{}", Last name: "{}" and username: "{}"",                user.getId(), user.getPerson().getFirstName(), user.getPerson().getLastName(), user.getUsername());        return "ActivatedAccount";    }}

您的KeyService使用方法findKeyByKeyString()方法调用一些Spring Data JPA存储库.该方法导致Spring Data JPA爆炸,因为缺少某些查询参数.

在org.springframework.data.jpa.repository.query.StringQuery.getBindingFor(StringQuery.java:104)上放置一个条件断点,匹配if!StringUtils.hasText(name)以查看正在发生的事情,或查看findKeyByKeyString()方法.

免责声明:本网信息来自于互联网,目的在于传递更多信息,并不代表本网赞同其观点。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,并请自行核实相关内容。本站不承担此类作品侵权行为的直接责任及连带责任。如若本网有任何内容侵犯您的权益,请及时联系我们,本站将会在24小时内处理完毕。
相关文章
返回顶部