è possibile semplicemente registrare tutto il contenuto del file delle proprietà caricato da spring con <context:property-placeholder />
?Come registrare le proprietà caricate da Spring?
Grazie
è possibile semplicemente registrare tutto il contenuto del file delle proprietà caricato da spring con <context:property-placeholder />
?Come registrare le proprietà caricate da Spring?
Grazie
Si può fare in questo modo:
<context:property-placeholder properties-ref="myProperties"/>
<bean id="myProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
.. locations
</list>
</property>
</bean>
e aggiungere un fagiolo di registrazione simile a quella riportata di seguito (qui annotazioni based e con slf4j api):
@Component
public class PropertiesLogger {
private static Logger logger = LoggerFactory.getLogger(PropertiesLogger.class);
@Resource("myProperties")
private Properties props;
@PostConstruct
public void init() {
for (Map.Entry<Object, Object> prop : props.entrySet()) {
logger.debug("{}={}", prop.getKey(), prop.getValue());
}
}
}
È può impostare il livello di registro di org.springframework.core.env.PropertySourcesPropertyResolver
su "debug". Quindi, sarai in grado di vedere il valore delle proprietà durante la risoluzione.
Aggiornamento: non più vero. Vedi http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/core/env/PropertySourcesPropertyResolver.html#logKeyFound-java.lang.String-org.springframework.core.env .PropertySource-java.lang.Object- che legge 'A 4.3.3, questo non registra più il valore per evitare la registrazione accidentale di impostazioni sensibili. – dgtc
funziona solo se si dispone di un segnaposto di proprietà. – Walfrat