2013-01-13 13 views

risposta

2

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()); 
    } 
    } 
} 
+0

funziona solo se si dispone di un segnaposto di proprietà. – Walfrat

9

È 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.

+5

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

Problemi correlati