Polish "Add support for Spring WS auto WSDL/XSD exposure"

Closes gh-9635
This commit is contained in:
Stephane Nicoll 2017-09-25 15:20:55 +02:00
parent bb72a4abe1
commit 15de6531a5
2 changed files with 24 additions and 19 deletions

View File

@ -106,6 +106,11 @@ public class WebServicesAutoConfiguration {
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
@Override @Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)
throws BeansException { throws BeansException {
@ -125,33 +130,29 @@ public class WebServicesAutoConfiguration {
throws BeansException { throws BeansException {
} }
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
this.applicationContext = applicationContext;
}
private void registerBeans(String location, String pattern, Class<?> type, private void registerBeans(String location, String pattern, Class<?> type,
BeanDefinitionRegistry registry) { BeanDefinitionRegistry registry) {
Resource[] resources = new Resource[] {}; for (Resource resource : getResources(location, pattern)) {
try {
resources = this.applicationContext
.getResources(ensureTrailingSlash(location) + pattern);
}
catch (IOException ignored) {
}
for (Resource resource : resources) {
RootBeanDefinition beanDefinition = new RootBeanDefinition(type); RootBeanDefinition beanDefinition = new RootBeanDefinition(type);
ConstructorArgumentValues constructorArguments = new ConstructorArgumentValues(); ConstructorArgumentValues constructorArguments = new ConstructorArgumentValues();
constructorArguments.addIndexedArgumentValue(0, resource); constructorArguments.addIndexedArgumentValue(0, resource);
beanDefinition.setConstructorArgumentValues(constructorArguments); beanDefinition.setConstructorArgumentValues(constructorArguments);
registry.registerBeanDefinition( registry.registerBeanDefinition(
StringUtils.stripFilenameExtension(resource.getFilename()), StringUtils.stripFilenameExtension(resource.getFilename()),
beanDefinition); beanDefinition);
} }
} }
private Resource[] getResources(String location, String pattern) {
try {
return this.applicationContext
.getResources(ensureTrailingSlash(location) + pattern);
}
catch (IOException e) {
return new Resource[0];
}
}
private static String ensureTrailingSlash(String path) { private static String ensureTrailingSlash(String path) {
if (!path.endsWith("/")) { if (!path.endsWith("/")) {
return path + "/"; return path + "/";

View File

@ -6560,10 +6560,14 @@ your `Endpoints`.
The {spring-webservices-reference}[Spring Web Services features] can be easily accessed The {spring-webservices-reference}[Spring Web Services features] can be easily accessed
via the `spring-boot-starter-webservices` module. via the `spring-boot-starter-webservices` module.
Spring Boot can also automatically expose your WSDLs and XSDs using `SimpleWsdl11Definition` and `SimpleXsdSchema` beans can be automatically created for your
`spring.webservices.wsdl-locations` configuration property. For the detected WSDL and XSD WSDLs and XSDs respectively. To do so, configure their location:
files Boot will register beans of type `SimpleWsdl11Definition` and `SimpleXsdSchema`,
respectively.
[source,properties,indent=0]
----
spring.webservices.wsdl-locations=classpath:/wsdl
----