Spring MVC 通过@Value注解读取.properties配置内容,@value.properties

Spring MVC 通过@Value注解读取.properties配置内容,@value.properties

 

第一步:

在applicationContext.xml配置:

 1     <bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
 2         <property name="locations">
 3             <list>
 4                 <value>classpath:/config/*.properties</value>
 5             </list>
 6         </property>
 7     </bean>
 8     <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
 9         <property name="properties" ref="configProperties" />
10     </bean>    

第二步:

建立配置文件内容:

例如:userPageSize=5

第三步:

在Controller中使用注解获得配置项内容:

1 @Value("#{configProperties['userPageSize']}")
2 private String userPageSize; 

第四步:

后面的代码就可以使用userPageSize这个私有变量了,这个字符串的值就是我们配置文件中配置的5.

 

eclipse怎搭建springmvc +mybatis

 

SpringMVC+MyBatis+Freemarker 简单框架搭建(一)

一、开发环境:
Eclipse、Tomcat、SVN等请参见如下的帖子,很详细了。
www.iteye.com/topic/982182

svn和maven插件的安装:
1、先安装gef插件
地址:download.eclipse.org/tools/gef/updates/interim/
2、安装svn插件
地址:subclipse.tigris.org/update_1.6.x
3、maven插件
m2eclipse-core Update 地址: m2eclipse.sonatype.org/sites/m2e
m2eclipse-extras Update 地市: m2eclipse.sonatype.org/sites/m2e-extras
4、安装可能出现的问题
直接在线安装maven2 会出现依赖插件找不到的问题,无法安装。必须先安装gef 插件后才能安 装m2eclipse-core 插件,然而安装m2eclipse-extras 插件又依赖subclipse 插件。所以,三个插 件的正确的安装顺序是:gef插件 》subclipse插件 》m2eclipse插件

二、web.xml 和 applicationContext.xml 配置
1、web.xml文件配置:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="www.w3.org/2001/XMLSchema-instance"
xmlns="......余下全文>>
 

spring mvc + hibernate4 怎 读取配置文件 获取 JNDI数据原的名字

 

1,创建配置文件:jdbc.properties
db.driver=oracle.jdbc.driver.OracleDriver
db.url=jdbc:oracle:thin:@10.100.15.66:1521:cdgk
db.user=shbx_sn
db.password=shbx_sn
db.alias=OrclPool
db.houseKeepingTestSql=select sysdate from dual
db.characterEncoding=GBK
db.maximumConnectionCount=6
db.minimumConnectionCount=1
db.maximumActiveTime=19999999
db.jndiName=jbzh_sn
2,配置spring mvc
<bean id="propertyConfigurer" class="org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfigurer">
<constructor-arg ref="configurationEncryptor" />
<property name="location">
<!-- 此处引入配置文件 -->
<value>classpath:jdbc.properties</value>
</property>
</bean>

<!-- 使用连接池则屏蔽 'JNDI数据源',使用JNDI数据源,则屏蔽连接池,同时需要在weblogic建立jbzh_sn数据源 -->
<!-- 1. proxool连接池 -->
<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">
<!-- 此处使用配置文件中的属性 -->
<property name="driver" value="${db.driver}" />
<property name="driverUrl" value="${db.url}" />
<property name="user" value="${db.user}" />
<property name="password" value="${db.password}" />
<property name="alias" value="${db.alias}" />
<property name=&quo......余下全文>>

 

转自:http://www.bkjia.com/Javabc/870677.html

posted @ 2016-08-18 18:02  N神3  阅读(585)  评论(0编辑  收藏  举报