我想创建一个Restful 服务,但是当我尝试 url "http..:8080/appanalytix-web/requirementservice/saverequirements" 它不起作用
我的服务:
@Path("/requirementservice")
@Service("dimRequirementManager")
public class DimRequirementManagerImpl extends GenericManagerImpl<DimRequirement, Long> implements DimRequirementManager {
DimRequirementDao dimRequirementDao;
@Autowired
public DimRequirementManagerImpl(DimRequirementDao dimRequirementDao) {
super(dimRequirementDao);
this.dimRequirementDao = dimRequirementDao;
}
@PUT
@Path("/saverequirements")
@Consumes("application/json")
@Override
public void saveAllDimRequirements(List<DimRequirement> requirementList) {
dimRequirementDao.saveAllDimRequirements(requirementList);
}
}
是否需要有一个调度程序 servlet 才能使用 url ?由于这是我的服务,客户端将如何使用 HTTP PUT 或 POST 传递 json 字符串
编辑添加 servlet 后
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/restServices/*</url-pattern>
</servlet-mapping>
我在 web.xml 中添加了 servlet,我尝试了 url http..:8080/appanalytix-web/restServices/requirementservice/saverequirements 我收到以下错误
ERROR [tomcat-http--17] Dispatcher.error(38) | Exception occurred during processing request: There is no Action mapped for namespace [/] and action name [restServices/requirementservice/saverequirements] associated with context path [/appanalytix-web].
There is no Action mapped for namespace [/] and action name [restServices/requirementservice/saverequirements] associated with context path [/appanalytix-web]. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:534)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter.doFilter(StrutsExecuteFilter.java:88)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter.doFilter(StrutsPrepareFilter.java:82)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.vxl.appanalytix.webapp.filter.RequestAuthentication.doFilter(RequestAuthentication.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)