CAS WAR Overlay v6.1.6自定义REST接口返回404排查求助
Hey there, let's troubleshoot that 404 issue with your custom REST controller in CAS WAR Overlay v6.1.6. Here are the most common things you might have missed:
CAS won't automatically pick up your custom controller unless you tell it to scan your package. Head over to your overlay's src/main/resources/application.properties (or application.yml) and add this line:
cas.component-scan.base-packages=com.example
Make sure the package path matches the root of where your controller lives (e.g., com.example covers com.example.rest).
Double-check your controller class uses the right Spring annotations. CAS relies on standard Spring Web annotations to register endpoints. For example:
package com.example.rest; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/api/custom") public class CustomRestController { @GetMapping("/hello") public String sayHello() { return "Hello from custom CAS endpoint!"; } }
Ensure you have @RestController and a clear @RequestMapping (or specific method annotations like @GetMapping) to define your endpoint path.
Sometimes the overlay skips compiling custom classes if you don't run a clean build first. Try these commands in order:
./gradlew clean build ./gradlew run
This ensures your Java code is compiled and included in the CAS WAR file before starting the server.
CAS has strict security rules that might block your custom path by default. To allow access, add these lines to application.properties:
# Allow cross-origin requests if you're using Postman from a different origin cas.security.web.cors.enabled=true # Skip security checks for your custom endpoints (adjust if you need auth) cas.security.web.ignore-patterns=/api/custom/**
If CAS is running with its default context path (/cas), your full endpoint URL should include it. For example, if your controller maps to /api/custom/hello, the correct URL in Postman is:http://localhost:8080/cas/api/custom/hello
Check if your compiled controller exists in the build directory: look under build/classes/java/main/com/example/rest/ for CustomRestController.class. If it's missing, there might be an issue with your project structure (make sure files are under src/main/java, not another directory) or Gradle configuration.
内容的提问来源于stack exchange,提问作者Nishant Singh

