I have created some web services with a library of code that I have imported into my Spring-based Java web project.
my web.xml:
<servlet>
<servlet-name>serviceDispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/*servlet.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>serviceDispatcher</servlet-name>
<url-pattern>/services/*</url-pattern>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
My spring config:
<context:component-scan base-package="project.thc, global.libraries" />
My Service Controller:
package global.libraries.webservices;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import global.libraries.util.EntityUtil;
@Controller
public class THCWebServices {
public static final String SOURCE_NAME = EntityUtil.Reflection.getClassName(new THCWebServices().getClass(), false);
@RequestMapping(value=WebServicesConfig.ServiceUrl.userAuthenticationService, method = RequestMethod.GET, produces = "application/json")
public @ResponseBody String userAuthenticationService(@RequestParam String key, @RequestParam String project, @RequestParam String username, @RequestParam String password, HttpServletRequest request) {
WebServiceResponse serviceResponse = new WebServiceResponse(project);
WebServiceParameters serviceParameters = new WebServiceParameters(request, project, key);
if (!serviceResponse.isMaintenance()) {
serviceResponse.addMethodResult(WebServiceMethods.userAuthorizationService(serviceParameters));
}
return EntityUtil.convertToJson(serviceResponse, serviceParameters.getLogDirectory());
}
}
Service URL:
WebServicesConfig.ServiceUrl.userAuthenticationService = "/authorization/validate";
I am using URL http://localhost:[port]/THC/services/authorization/validate and I keep getting 404 errors.
I have been unable to identify why the controller in the global library is not identified. Other services contained within the local project source load just fine.
Is it possible to load web services into a project from a JAR (library)?
Can anyone see errors in my configuration that would prevent the service from being detected by the component scan?
EDIT NOTES: Added serviceDispatcher configuration from web.xml. Added reference for WebServicesConfig.ServiceUrl.userAuthenticationService. Updated example URL for localhost