Spring 3, get file properties from source with @Value

Creare un file di properties dentro la cartella resources:

configurationFBM.properties

prova= bohhhh

Modificare il file di configurazione di spring:

<beans xmlns:context=”http://www.springframework.org/schema/context” xmlns:util=”http://www.springframework.org/schema/util” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns=”http://www.springframework.org/schema/beans” xsi:schemalocation=”http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd”>

<context:component-scan base-package=”com.fbm”>
       <util:properties id=”configurationFBM” location=”classpath:/configurationFBM.properties”>

</util:properties></context:component-scan></beans>

Da dentro il codice si può accedere ad una proprietà del file di properties con la seguente annotation:

@Value(“#{configurationFBM[‘prova’]}”)
String someValue;
(Visited 32 times, 1 visits today)

Lascia un commento

Il tuo indirizzo email non sarà pubblicato.