【发布时间】:2016-11-22 04:54:27
【问题描述】:
如果我有 java 配置,我不太明白如何为 Spring Http Invoker 配置 web.xml 文件。
这里是配置:
@Configuration
@Import(JdbcConfiguration.class)
@EnableWebMvc
public class HttpInvokerConfig {
@Bean
public HttpInvokerServiceExporter contactExporter(){
HttpInvokerServiceExporter contactExporter = new HttpInvokerServiceExporter();
contactExporter.setServiceInterface(ContactDao.class);
return contactExporter;
}
@Bean
public HttpInvokerProxyFactoryBean remoteContactService(){
HttpInvokerProxyFactoryBean remoteContactService = new HttpInvokerProxyFactoryBean();
remoteContactService.setServiceUrl("http://localhost:8080/experimental/ContactService");
remoteContactService.setServiceInterface(ContactDao.class);
return remoteContactService;
}
}
这里是 web.xml:
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Spring HTTP Invoker Sample</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>contactExporter</servlet-name>
<servlet-class>
org.springframework.web.context.support.HttpRequestHandlerServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>contactExporter</servlet-name>
<url-pattern>/remoting/ContactService</url-pattern>
</servlet-mapping>
</web-app>
我需要在 context-param 中指定什么而不是 xml 的路径,是否可以在没有 web.xml 的情况下运行调用程序(如 servlet 3.0 规范)?
【问题讨论】:
-
看看AbstractAnnotationConfigDispatcherServletInitializer,扩展这个类,你的类将作为
web.xml文件的xml等价物工作。 -
欲了解更多信息,请查看post。
标签: java xml spring spring-mvc