gpt4 book ai didi

spring - 奇怪的异常 : "Name must not be null or empty!"

转载 作者:行者123 更新时间:2023-12-03 18:11:58 41 4
gpt4 key购买 nike

我在 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(带有 spring 表单验证等)

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

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

有没有人知道为什么会发生这个错误,或者有什么线索可以知道我如何找出它发生的原因?
@Controller
public 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正在使用方法调用一些 Spring Data JPA 存储库 findKeyByKeyString()方法。该方法导致 Spring Data JPA 爆炸,因为缺少某些查询参数。

org.springframework.data.jpa.repository.query.StringQuery.getBindingFor(StringQuery.java:104) 上放置一个条件断点如果 !StringUtils.hasText(name) 匹配查看发生了什么,或查看 findKeyByKeyString()方法。

关于spring - 奇怪的异常 : "Name must not be null or empty!",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22748721/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com