我正在嘗試使用Java-Config來設置webservices項目(目前是SOAP--但最終會添加REST)。不幸的是,我還沒有能夠自動公開WSDL(據推測,Spring可以基於XSD生成並公開它)。Spring-ws javaconfig位置轉換
我發現的唯一文檔在定義servlet(web.xml)時使用xml配置。
<init-param>
<param-name>transformWsdlLocations</param-name>
<param-value>true</param-value>
</init-param>
您如何使用Java-config完成此操作?
WebApplicationInitializer
public class WebApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
/**
* {@inheritDoc}
*/
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] {WebSecurityConfiguration.class};
}
/**
* {@inheritDoc}
*/
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[] {WebServicesConfiguration.class};
}
/**
* {@inheritDoc}
*/
@Override
protected String[] getServletMappings() {
// get all mappings
return new String[] { "/" };
}
WebServicesConfiguration
@EnableWs
@Configuration
@ComponentScan("com.questsoftware")
public class WebServicesConfiguration extends WsConfigurationSupport {
@Bean
public XsdSchema schema() {
return new SimpleXsdSchema(new ClassPathResource("lookup.xsd"));
}
@Bean
public DefaultWsdl11Definition defaultWsdl11Definition() {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setTargetNamespace("http://com/[mycompany]/Lookup");
wsdl11Definition.setPortTypeName("Lookup");
wsdl11Definition.setLocationUri("/Lookup");
wsdl11Definition.setSchema(schema());
return wsdl11Definition;
}
是明確的 - 我也有一個WebApplicationConfiguration(REST) - 但我沒有在WebApplicationInitializer加入它尚未(RAN首先解決這個問題)。
WebApplicationConfiguration
@EnableWebMvc
@EnableAspectJAutoProxy(proxyTargetClass = true)
@Configuration
@ComponentScan("com.mycompany")
public class WebApplicationConfiguration extends WebMvcConfigurerAdapter {
/**
* Defines {@link JdbcTemplate} as a Spring managed bean.
*
* @return
*/
@Bean
public JdbcTemplate jdbcTemplate() {
return new JdbcTemplate(dataSource());
}
@Bean
public DataSource dataSource() {
...
return dataSource;
}
/**
* Defines a {@link ViewResolver} as a Spring managed bean.
*
* @return the viewResolver
*/
@Bean
public ViewResolver viewResolver() {
final InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/pages");
resolver.setSuffix(".jsp");
return resolver;
}
/**
* Registers resource handlers with Spring.
*
* @param registry the {@link ResourceHandlerRegistry}
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/view/**").addResourceLocations("/view/");
}
參考
http://docs.spring.io/spring-ws/sites/2.0/reference/html/server.html#server-automatic-wsdl-exposure