Bonjour
J'utilise Spring 3.3 et j'ai un problème pour récupérer dans une classe Java une properties qui est dans un fichier de configuration
Voici ce que j'ai mis dans mon fichier XML:
et ma classe Java
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xmlns:ftp="http://www.springframework.org/schema/integration/ftp" xmlns:si="http://www.springframework.org/schema/integration" xmlns:batch="http://www.springframework.org/schema/batch" xmlns:task="http://www.springframework.org/schema/task" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.1.xsd http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp-2.1.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <context:annotation-config /> <context:component-scan base-package="my.package" /> <context:property-placeholder location="file:///${PATH_CONFIGURATION}\file.properties"/> ....
et dans le log de ma méthode myMethod j'ai la trace myProperrties: null
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 public class MyClass { private Logger logger = LoggerFactory .getLogger(MyClass .class); @Value("${my.key}") private String myProperrties; public void myMethod() { logger.debug("myProperrties:" + myProperrties); } }
J'ai essayé plusieurs autres méthodes mais sans succès. Notamment en déclarant le bean dans mon fichier XML mais là aussi j'ai toujours une valeur nulle
Si quelqu'un à une idée je suis preneur
Merci
Partager