2010-07-14 13 views
8

Vorrei sapere se esiste la possibilità di impostare un attributo in web.xml utilizzando il file delle proprietà. Ad esempio il web.xml:Come impostare il valore in web.xml utilizzando il file delle proprietà

<context-param>
<param-name>Map.MyJNDI</param-name>
<param-value>java:comp/env/jdbc/${my.computer}</param-value>
</context-param>

e application.properties sarebbe:

# My computer's name
my.computer=eniac

Grazie per le risposte. Tomas

+0

controllare questi: - http://stackoverflow.com/questions/15380817/properties-file-as-init-param-in-web-xml - http://stackoverflow.com/questions/12099008/how-to-include-valori-da-proprietà-file-in-web-xml – Chepech

risposta

1

non è possibile impostare il valore dal file Properties ma è possibile impostare il file delle proprietà e leggerlo in fase di esecuzione.

<context-param> 
    <param-name>propfile</param-name> 
    <param-value>myproject.properties</param-value> 
</context-param> 

quindi leggere il file delle proprietà in fase di esecuzione.

MyServlet myServlet = new MyServlet(); 

Properties properties = new Properties(); 
// get the properties file name 
String propfile = myServlet.getInitParameter("propfile"); 

// load the file 
properties.load(getClass().getClassLoader().getResourceAsStream(propfile)); 

// get the desire properties 
Object propName = properties.get("my.computer"); 
// out.println(propName.toString()); 

spero che questo aiuti anche altri.

0

Non è possibile avere valori sostituiti in web.xml in questo modo.

Una possibilità che posso suggerire, se possibile, solo avere un web.xml modello con segnaposto per i valori e durante la costruzione per ogni ambiente ha un passo di processo di generazione che sostituirà valori richiesti dalla richiesta file delle proprietà di tale ambiente.

Problemi correlati