wmcoo
岁月神偷
:: :: :: :: ::
管理
<
2015年6月
>
日
一
二
三
四
五
六
31
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
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
文章分类
(22)
Hibernate(4)
J2EE(3)
Java(1)
JavaScript
MySQL
Spring(13)
SQLServer(1)
Struts
WebService
搜索
最新评论
1. re: Spring 声明式事务,propagation属性列表
可以对一些专业名词在做具体分析,就完美啦
--野狼
2. re: Spring 在配置中使用*.properties
王二伟
--儿
3. dsad
fdsfa
--fdsaf
4. re: Spring MVC 的请求参数获取
评论内容较长,点击标题查看
--zuidaima
5. re: Spring MVC 拦截器
评论内容较长,点击标题查看
--legend
Spring 在配置中使用*.properties
xml
<?
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:util
=
"
http://www.springframework.org/schema/util
"
xsi:schemaLocation
=
"
http://www.springframework.org/schema/beans
http:
//
www.springframework.org/schema/beans/spring-beans-3.0.xsd
http:
//
www.springframework.org/schema/context
http:
//
www.springframework.org/schema/context/spring-context-3.0.xsd
http:
//
www.springframework.org/schema/util
http:
//
www.springframework.org/schema/util/spring-util-3.0.xsd">
<
context:annotation
-
config
/>
<!--
picks up and registers AppConfig as a bean definition
-->
<
context:component
-
scan base
-
package
=
"
com.web.spring.other
"
/>
<
bean
class
=
"
com.web.spring.other.AppConfig
"
/>
访法一
<
context:property
-
placeholder location
=
"
classpath:jdbc.properties
"
/>
方法二
<
util:properties id
=
"
jdbcProperties
"
location
=
"
classpath:jdbc.properties
"
/>
</
beans
>
实现一
package
com.web.spring.other;
import
org.springframework.beans.factory.annotation.Value;
import
org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration;
import
org.springframework.context.annotation.ImportResource;
@Configuration
@ImportResource(
"
classpath*:spring/spring-properties.xml
"
)
public
class
AppConfig {
private
@Value(
"
${jdbc.driverClassName}
"
) String driverClassName;
@Bean(initMethod
=
"
init
"
)
public
JDBCBean jdbc(){
JDBCBean jdbc
=
new
JDBCBean();
jdbc.setDriverClassName(driverClassName);
return
jdbc;
}
}
jdbc.driverClassName=org.hsqldb.jdbcDriver
实现二
package
com.web.spring.other;
import
org.springframework.beans.factory.annotation.Value;
import
org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration;
@Configuration
public
class
AppConfig {
private
@Value(
"
#{jdbcProperties.driverClassName}
"
) String driverClassName;
//private @Value("#{jdbcProperties['jdbc.driverClassName']}") String driverClassName;
@Bean(initMethod
=
"
init
"
)
public
JDBCBean jdbc(){
JDBCBean jdbc
=
new
JDBCBean();
jdbc.setDriverClassName(driverClassName);
return
jdbc;
}
}
driverClassName=org.hsqldb.jdbcDriver
posted on 2010-09-29 12:09
岁月神偷
阅读(5555)
评论(1)
编辑
收藏
所属分类:
Spring
Feedback
#
re: Spring 在配置中使用*.properties
2015-06-29 16:15 |
儿
王二伟
回复
更多评论
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
Chat2DB
C++博客
博问
管理
相关文章:
Java类获取spring 容器的bean
Spring 自定义搜索,注解BEAN
Spring 注解@Transactional
Spring 声明式事务,propagation属性列表
Spring AOP管理事务
Spring MVC 拦截器
SpringMVC 中的数据验证
Spring MVC的自动转换功能 HttpMessageConverter
Spring MVC 的请求参数获取
Spring 的MVC @RequestMapping