我正在使用Sping Boot 开发一个社区网站,当我尝试测试“注册”功能时,它显示此错误:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Aug 16 01:02:01 EDT 2023
There was an unexpected error (type=Internal Server Error, status=500).
org/apache/commons/lang3/StringUtils
java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
at com.nowcoder.community.service.UserService.register(UserService.java:48)
at com.nowcoder.community.controller.LoginController.register(LoginController.java:26)
因为它提到了从“if(StringUtils.isBlank(user.getUsername()”开始的第48行
public Map<String, Object> register(User user) {
Map<String, Object> map = new HashMap<>();
// Empty value
if (user == null) {
throw new IllegalArgumentException("User cannot be null!");
}
if (StringUtils.isBlank(user.getUsername())) {
map.put("usernameMsg", "Username cannot be empty!");
return map;
}
if (StringUtils.isBlank(user.getPassword())) {
map.put("passwordMsg", "Password cannot be empty!");
return map;
}
if (StringUtils.isBlank(user.getEmail())) {
map.put("emailMsg", "Email cannot be empty!");
return map;
}
我在pom.xml文件中添加了commons-lang 3
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.13.0</version>
</dependency>
我用的是IntelliJ,不知道是不是相关的。我已经导入了import org.apache.commons.lang3.StringUtils;
2条答案
按热度按时间oalqel3c1#
检查JAR的Java构建路径。
如果要在服务器上部署并运行它,请尝试将JAR文件放在ApacheTomcat安装的\lib子文件夹中。
fd3cxomn2#
我想你可以导入这个包import org.springframework.util.StringUtils;