SOAP Web Service(Java)调用报错:405状态码问题排查求助
Hey there, let's work through this 405 Method Not Allowed error you're facing with your CXF SOAP service. I've run into similar issues before, so here are the most common checks and fixes to try:
1. Verify Your CXF Servlet Mapping in web.xml
First, make sure your CXFServlet is correctly mapped to handle requests for your service endpoints, and isn't accidentally restricting HTTP methods:
- Double-check that the
url-patternfor CXFServlet covers your service path (e.g.,/services/*). A misconfigured mapping might send requests to the wrong servlet (like Tomcat's default servlet) that doesn't accept POST. - Example of a valid CXFServlet config:
<servlet> <servlet-name>CXFServlet</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> - Also, check for any
<security-constraint>blocks that might explicitly restrict HTTP methods (e.g., only allowing GET). SOAP requests require POST, so these constraints could block valid calls.
2. Validate SOAPUI Request Details
SOAP requests have strict requirements, and small misconfigs here often cause 405s:
- Ensure you're using the POST method (SOAP doesn't support GET for method invocations). In SOAPUI, switch to the "Raw" tab of your request to confirm the first line starts with
POST /your-full-service-path HTTP/1.1. - Check the
Content-Typeheader: it must betext/xml(for SOAP 1.1) orapplication/soap+xml(for SOAP 1.2). If SOAPUI auto-set the wrong value, this will trigger a 405.
3. Check Endpoint Configuration in applicationContext.xml
Make sure your endpoint's address aligns with the URL you're calling in SOAPUI:
- If your endpoint is configured like this:
The full invocation URL should be<jaxws:endpoint id="yourService" implementor="com.your.package.YourServiceImpl" address="/YourService"/>http://your-domain:port/your-app-context/services/YourService(don't miss the/servicesprefix from your servlet mapping). - Also, check if you've set an
allowedMethodsattribute on the endpoint—if present, ensure it includesPOST.
4. Rule Out Security Config Conflicts
Your securityContext.xml might be interfering with valid POST requests:
- Temporarily comment out security-related beans/interceptors and test the service. If the 405 goes away, you know the issue is in your security setup.
- Look for
<intercept-url>orrequest-matcherrules that restrict HTTP methods for your service path—update them to allow POST.
5. Dig Into Server Logs
Server logs (like Tomcat's catalina.out or your app's specific logs) will often give more context about why the 405 is happening:
- You might see messages like "Method POST is not allowed" or details about which servlet processed the request (confirm it's CXFServlet, not another one).
- These logs can point you directly to the root cause if the above checks don't reveal it.
内容的提问来源于stack exchange,提问作者jaxonjma

