Java-Configを使用して、webservicesプロジェクトをセットアップしようとしています(現在はSOAPですが、最終的にRESTを追加します)。残念ながら、私はWSDLを自動的に公開することができませんでした(おそらく、SpringはXSDに基づいてそれを生成し、公開することができます)。Spring-ws javaconfigロケーション変換
サーブレット(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