{"record":{"id":"b1a05c5d00be7f36","repo":"spring-projects/spring-security","slug":"advicemode-advicemode-is-not-supported","errorCode":null,"errorMessage":"AdviceMode '{adviceMode}' is not supported","messagePattern":"AdviceMode '(.+?)' is not supported","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"config/src/main/java/org/springframework/security/config/annotation/method/configuration/MethodSecuritySelector.java","lineNumber":99,"sourceCode":"\t}\n\n\tprivate static final class AutoProxyRegistrarSelector extends AdviceModeImportSelector<EnableMethodSecurity> {\n\n\t\tprivate static final String[] IMPORTS = new String[] { AutoProxyRegistrar.class.getName(),\n\t\t\t\tMethodSecurityAdvisorRegistrar.class.getName() };\n\n\t\tprivate static final String[] ASPECTJ_IMPORTS = new String[] {\n\t\t\t\tMethodSecurityAspectJAutoProxyRegistrar.class.getName() };\n\n\t\t@Override\n\t\tprotected String[] selectImports(@NonNull AdviceMode adviceMode) {\n\t\t\tif (adviceMode == AdviceMode.PROXY) {\n\t\t\t\treturn IMPORTS;\n\t\t\t}\n\t\t\tif (adviceMode == AdviceMode.ASPECTJ) {\n\t\t\t\treturn ASPECTJ_IMPORTS;\n\t\t\t}\n\t\t\tthrow new IllegalStateException(\"AdviceMode '\" + adviceMode + \"' is not supported\");\n\t\t}\n\n\t}\n\n}\n","sourceCodeStart":81,"sourceCodeEnd":105,"githubUrl":"https://github.com/spring-projects/spring-security/blob/96852e8860138a482cb13d1479573f24ff6443c6/config/src/main/java/org/springframework/security/config/annotation/method/configuration/MethodSecuritySelector.java#L81-L105","documentation":"MethodSecuritySelector is an ImportSelector that picks the method-security configuration based on the AdviceMode declared on @EnableGlobalMethodSecurity. Only PROXY and ASPECTJ are implemented; any other value throws this IllegalStateException. In practice this only happens with a corrupt/invalid annotation value.","triggerScenarios":"Setting adviceMode to a value other than PROXY or ASPECTJ on @EnableGlobalMethodSecurity; custom AdviceMode enums supplied via a patched annotation; programmatic annotation construction with a null or unexpected AdviceMode.","commonSituations":"Hand-edited or generated annotations with wrong adviceMode; upgrading Spring Security where new AdviceMode values exist but the selector does not support them; copy-paste mistakes in meta-annotations.","solutions":["Set adviceMode = AdviceMode.PROXY (the default) on @EnableGlobalMethodSecurity","If you need AspectJ weaving, set adviceMode = AdviceMode.ASPECTJ","Remove any custom/invalid AdviceMode value; only the two enum constants are supported"],"exampleFix":"// before\n@EnableGlobalMethodSecurity(prePostEnabled = true, adviceMode = AdviceMode.ASPECTJ)\n// after (if not using AspectJ)\n@EnableGlobalMethodSecurity(prePostEnabled = true)","handlingStrategy":"validation","validationCode":"AdviceMode mode = enableGlobalMethodSecurity.adviceMode();\nif (mode != AdviceMode.PROXY && mode != AdviceMode.ASPECTJ) {\n    throw new IllegalArgumentException(\"Unsupported adviceMode: \" + mode);\n}","typeGuard":null,"tryCatchPattern":"try {\n    ctx.refresh();\n} catch (BeanCreationException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"AdviceMode\")) {\n        // fall back to default PROXY configuration\n    }\n    throw e;\n}","preventionTips":["Only use AdviceMode.PROXY or AdviceMode.ASPECTJ on @EnableGlobalMethodSecurity","Do not construct the annotation metadata programmatically with custom AdviceMode values","Keep adviceMode at its default unless you specifically need AspectJ"],"tags":["spring-security","spring","advice-mode","import-selector"],"backgroundTag":"invalid-enum-value","analyzedSha":"96852e8860138a482cb13d1479573f24ff6443c6","analyzedAt":"2026-09-10T23:25:23.477Z","contentChangedAt":"2026-09-10T23:25:23.477Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}