2010-07-14 38 views
8

me gustaría saber si hay posibilidad de establecer un atributo en web.xml mediante el uso de archivo de propiedades. Por ejemplo, el web.xml:Cómo establecer el valor en web.xml utilizando archivo de propiedades

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

y application.properties sería:

# My computer's name
my.computer=eniac

Gracias por responder. Tomas

+0

comprobar estos: - http://stackoverflow.com/questions/15380817/properties-file-as-init-param-in-web-xml - http://stackoverflow.com/questions/12099008/how-to-include-values-from-properties-file-into-web-xml – Chepech

Respuesta

1

no puede establecer el valor desde el archivo Properties pero puede establecer el archivo de propiedad y leerlo en tiempo de ejecución.

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

luego lea el archivo de propiedad en tiempo de ejecución.

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()); 

Espero que esto ayude a otros también.

0

No puede haber valores sustituidos en web.xml como ese.

Una opción Puedo sugerir si es posible solo tener una plantilla web.xml con marcador de posición para valores y durante la compilación para cada entorno tener un paso en el proceso de compilación que sustituirá los valores requeridos del archivo de propiedades requeridas de ese entorno.

Cuestiones relacionadas