我在Web服務初學者使用Web服務
- 春3.0和彈簧webmvc的portlet 3.0
- javax.portlet 2.0
我控制器如下所示
@Controller(value = "myController")
@RequestMapping(value = "**VIEW**")
public class MyController {
// Controller logic
}
現在,我想在Portlet環境中使用RESTful API創建Web Service。 請指導我如何編寫將返回JSON或XML數據的Web服務。
我仍在掙扎Web服務沒有得到WS調用。
我貼我的conf文件
- 的web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/itemCatalog-portlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>view-servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>view-servlet</servlet-name>
<url-pattern>/WEB-INF/servlet/view</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>webServiceTest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>webServiceTest</servlet-name>
<url-pattern>/myWebService/*</url-pattern>
</servlet-mapping>
項目-portlet.xml中
<aop:aspectj-autoproxy /> <context:component-scan base-package="com.main.mypackage" /> <bean class="org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="webBindingInitializer"> <bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer"> <property name="propertyEditorRegistrars"> <list> <ref bean="myPropertyEditorRegistrar" /> </list> </property> </bean> </property> </bean> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basenames"> <list> <value>content.Language-ext</value> </list> </property> </bean> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> <bean name="jsonView" class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"> <property name="prefixJson" value="false" /> </bean> <tx:annotation-driven transaction-manager="txManager" />
WebServiceTest的-servlet.xml中
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
- 的portlet.xml
itemCatalog org.springframework.web.portlet.DispatcherPortlet text/html的 視圖 content.Language-EXT
控制器
@Controller 公共類WebServiceTest的{
@RequestMapping(值= 「/爲MyWebService /測試」,方法= RequestMethod.GET) 公共字符串TestMethod的(){ 回報的「hello world!SUCCESS「; }
}
我試圖用
localhost來打:8080:/ myappname /爲MyWebService /測試
沒有得到結果
我可以使用DispatcherServlet配置嗎?配置Web服務 – Ketan