タイトルの通り、@Valueで指定した値が取得できません。
下記のコントローラにリクエストを送ると${test.property}がそのままの形で出力されます。
this_is_testが出力されるようにしたいです。
■javaファイル
java
1@RestController 2@RequestMapping(value = "/hoge") 3public class HogeController{ 4 5 @Value("${test.property}") 6 private String test; 7 8 @RequestMapping(value = "", method = RequestMethod.POST) 9 public String post( 10 final HttpServletRequest request, 11 final HttpServletResponse response){ 12 System.out.println(test); 13 return test; 14 } 15}
■ field.properties
properties
1test.property=this_is_test 2default.db.driverClassName=org.postgresql.Driver 3default.db.url=jdbc:postgresql://localhost:5432/hoge 4default.db.username=hoge 5default.db.password=hoge
■ applicationContext.xml
xml
1<?xml version='1.0' encoding='UTF-8' ?> 2<beans xmlns="http://www.springframework.org/schema/beans" 3xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4xmlns:p="http://www.springframework.org/schema/p" 5xmlns:aop="http://www.springframework.org/schema/aop" 6xmlns:tx="http://www.springframework.org/schema/tx" 7xmlns:context="http://www.springframework.org/schema/context" 8xmlns:mvc="http://www.springframework.org/schema/mvc" 9xmlns:util="http://www.springframework.org/schema/util" 10xsi:schemaLocation="http://www.springframework.org/schema/beans 11http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 12http://www.springframework.org/schema/aop 13http://www.springframework.org/schema/aop/spring-aop-4.2.xsd 14http://www.springframework.org/schema/tx 15http://www.springframework.org/schema/tx/spring-tx-4.2.xsd 16http://www.springframework.org/schema/context 17http://www.springframework.org/schema/context/spring-context-4.2.xsd 18http://www.springframework.org/schema/mvc 19http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd"> 20 21<context:property-placeholder location="classpath:properties/*.properties" order="0"/> 22<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" /> 23 24<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> 25<property name="driverClassName" value="${default.db.driverClassName}" /> 26<property name="url" value="${default.db.url}" /> 27<property name="username" value="${default.db.username}" /> 28<property name="password" value="${default.db.password}"/> 29<property name="defaultAutoCommit" value="false" /> 30</bean> 31 32<bean id="transactionManager" 33 class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 34 <property name="dataSource" ref="dataSource" /> 35</bean> 36 37<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 38 <property name="dataSource" ref="dataSource" /> 39</bean> 40 41<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 42 <property name="basePackage" value="jp.hoge.mapper" /> 43 <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /> 44</bean> 45 46<context:annotation-config /> 47<context:component-scan base-package="jp.hoge.*" /> 48<mvc:annotation-driven /> 49 50</beans> 51
なお、field.propertiesの配置場所はsrc/main/resources直下になります。
1つ不思議なのがapplicationContext.xmlでのデータベースの設定ではちゃんとプロパティの設定が効いており、field.propertiesで設定した値が入ります。
@Valueを使うとプロパティの値が取得できない状態です。
解決方法がわからず困っております。
お手数をおかけしますがお力添えをいただけると大変幸いです。
よろしくお願いいたします。

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。