Documento Primavera Bota diz que podemos definir propriedades no arquivo application.properties.
Mas eu não posso encontrar um documento que lista propriedades disponíveis que podem ser definidas.
Onde posso encontrar tal documento?
Por exemplo, eu quero definir documentRoot para servlet embutido.
Descobri que o método setDocumentRoot () é implementado em AbstractEmbeddedServletContainerFactory.java.
Mas eu não sei quando ou onde para chamar o método, ou o nome da propriedade que pode ser definida no application.properties.
Eu acho que deveria ser fácil, já que muito propósito de Primavera Bota é facilitar a configuração.
Desde já, obrigado.
ATUALIZAR:
Como M. Deinum sugggested, eu adicionei 'server.document-root: someDirectoryName' para os application.properties, mas seguindo erro ocorreu.
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'document-root' of bean class [org.springframework.boot.context.embedded.properties.ServerProperties]: Bean property 'document-root' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1057)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:915)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:82)
at org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:730)
at org.springframework.validation.DataBinder.doBind(DataBinder.java:626)
at org.springframework.boot.bind.RelaxedDataBinder.doBind(RelaxedDataBinder.java:78)
at org.springframework.validation.DataBinder.bind(DataBinder.java:611)
at org.springframework.boot.bind.PropertiesConfigurationFactory.doBindPropertiesToTarget(PropertiesConfigurationFactory.java:232)
at org.springframework.boot.bind.PropertiesConfigurationFactory.bindPropertiesToTarget(PropertiesConfigurationFactory.java:204)
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessAfterInitialization(ConfigurationPropertiesBindingPostProcessor.java:312)
... 31 more
Eu acho que é devido à forma como org.springframework.boot.context.embedded.properties.ServerProperties implementadas. (Veja https://github.com/spring-projects/spring-boot/blob/97cb7f096798ecd016de71f892fa55585d45f5eb/spring-boot/src/main/java/org/springframework/boot/context/embedded/properties/ServerProperties.java )
Declara '@ConfigurationProperties (name = server, ignoreUnknownFields = false)'. Então, ele gerencia as propriedades de aplicação que começa com 'servidor', e disallowes nome da propriedade desconhecida.
E ele não suporta documentRoot getter / setter.
BTW, classe ServerProperties é feita para um feijão por org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration (Veja https://github.com/spring-projects/spring-boot/blob/97cb7f096798ecd016de71f892fa55585d45f5eb/spring-boot-autoconfigure/src /main/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.java ) de modo que ele pode participar no processo de configuração.
Então, eu tentei implementar ServerProperties-como um e ServerPropertiesAutoConfiguration-como um eu mesmo.
O código é a seguinte:
package com.sample.server;
import java.io.File;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SampleConfiguration
{
@Bean
public SampleServerProperties sampleServerProperties()
{
return new SampleServerProperties();
}
@ConfigurationProperties(name = sample.server)
public static class SampleServerProperties
implements EmbeddedServletContainerCustomizer
{
private String documentRoot;
public String getDocumentRoot()
{
return documentRoot;
}
public void setDocumentRoot(String documentRoot)
{
System.out.println(############## setDocumentRoot);
this.documentRoot = documentRoot;
}
@Override
public void customize(ConfigurableEmbeddedServletContainerFactory factory)
{
if (getDocumentRoot() != null)
{
factory.setDocumentRoot(new File(getDocumentRoot()));
}
}
}
}
E acrescentou seguinte linha application.properties.
sample.server.documentRoot: someDirectoryName
... E funciona!
SetDocumentRoot ############## é impresso para o console, e a raiz do documento é realmente definido.
Então, eu estou feliz agora, mas é este o caminho certo para fazê-lo?













