代码之家  ›  专栏  ›  技术社区  ›  AlpacaWarrior

java.lang.NoClassDefFoundError:org/apache/commons/lang3/StringUtils

  •  0
  • AlpacaWarrior  · 技术社区  · 3 年前

    我正在使用Spring 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)

    正如它提到的第48行从“if(StringUtils.isBlank(user.getUsername())”开始

    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-lang3

            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>3.13.0</version>
            </dependency>

    我正在使用IntelliJ,不确定它是否相关。 我已经导入了导入org.apache.commons.lang3.StringUtils;

    1 回复  |  直到 3 年前
        1
  •  0
  •   Souhaila    3 年前

    检查JAR的Java构建路径。

    如果您正在部署它并在服务器上运行它,请尝试将JAR文件放在Apache Tomcat安装的\lib子文件夹中。

        2
  •  0
  •   shuai shao    3 年前

    我想你可以进口这个包裹 导入org.springframework.util.StringUtils;