我想创建 Restful service ,但是当我尝试使用网址“http ..:8080 / appanalytix-web / requirementservice / saverequirements”时,它无法正常工作
Myservice:
@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 String编辑后添加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)
答案 0 :(得分:0)
您必须拥有一个servlet,否则@Path
注释不会执行任何操作。
在saveAllDimRequirements
方法中 - 您必须使用put,因为您拥有@PUT
注释。