{"record":{"id":"ad78aeb230b20137","repo":"macrozheng/mall-learning","slug":"error-ad78ae","errorCode":null,"errorMessage":"用户名或密码错误","messagePattern":"用户名或密码错误","errorType":"exception","errorClass":"UsernameNotFoundException","httpStatus":null,"severity":"error","filePath":"mall-tiny-05/src/main/java/com/macro/mall/tiny/config/MallSecurityConfig.java","lineNumber":31,"sourceCode":" * @description 自定义配置，用于配置如何获取用户信息\n * @date 2022/5/20\n * @github https://github.com/macrozheng\n */\n@Configuration\npublic class MallSecurityConfig {\n\n    @Autowired\n    private UmsAdminService adminService;\n\n    @Bean\n    public UserDetailsService userDetailsService() {\n        //获取登录用户信息\n        return username -> {\n            AdminUserDetails admin = adminService.getAdminByUsername(username);\n            if (admin != null) {\n                return admin;\n            }\n            throw new UsernameNotFoundException(\"用户名或密码错误\");\n        };\n    }\n}\n","sourceCodeStart":13,"sourceCodeEnd":35,"githubUrl":"https://github.com/macrozheng/mall-learning/blob/cd02c000e57c693e49f1f72986dbfa6e4c952e09/mall-tiny-05/src/main/java/com/macro/mall/tiny/config/MallSecurityConfig.java#L13-L35","documentation":"Identical to error 0 but in the mall-tiny-05 module: the UserDetailsService bean throws UsernameNotFoundException when no UmsAdmin row matches the username supplied to the authentication manager. Spring's DaoAuthenticationProvider invokes this during every login attempt, so any unknown username surfaces as this error before password checking happens.","triggerScenarios":"Authentication via POST /admin/login with a username absent from the database; adminService.getAdminByUsername(username) returns null.","commonSituations":"Fresh mall-tiny-05 deployment without importing the SQL seed data, wrong spring.datasource URL/profile, user was deleted or status changed, username typo or extra whitespace from the client.","solutions":["Confirm the username exists: SELECT * FROM ums_admin WHERE username = '...'","Load the project's seed SQL (mall_tiny schema + data) into the configured database","Verify datasource URL/credentials in application.yml match the intended environment","Create the account via the register API before logging in"],"exampleFix":"// before\nAdminUserDetails admin = adminService.getAdminByUsername(username);\nif (admin != null) { return admin; }\nthrow new UsernameNotFoundException(\"用户名或密码错误\");\n// after\nAdminUserDetails admin = adminService.getAdminByUsername(username.trim());\nif (admin != null) { return admin; }\nlog.warn(\"Unknown username login attempt: {}\", username);\nthrow new UsernameNotFoundException(\"用户名或密码错误\");","handlingStrategy":"try-catch","validationCode":"if (!username || !username.trim()) { throw new IllegalArgumentException(\"用户名不能为空\"); }\n// server check: SELECT COUNT(*) FROM ums_admin WHERE username = ?","typeGuard":null,"tryCatchPattern":"try {\n    authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));\n} catch (AuthenticationException e) {\n    throw new ApiException(\"用户名或密码错误\");\n}","preventionTips":["Seed the database on deployment (Flyway/Liquibase)","Check the active Spring profile before assuming user exists","Normalize usernames (trim, consistent case) at registration and lookup","Confirm the account was registered successfully before login"],"tags":["spring-security","authentication","login","jdbc"],"backgroundTag":"user-not-found","analyzedSha":"cd02c000e57c693e49f1f72986dbfa6e4c952e09","analyzedAt":"2026-09-07T23:16:08.059Z","contentChangedAt":"2026-09-07T23:16:08.059Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}