Linux安全网 - Linux操作系统_Linux 命令_Linux教程_Linux黑客

会员投稿 投稿指南 本期推荐:
搜索:
您的位置: Linux安全网 > Linux集群 > Architecture > » 正文

Spring 在配置中使用*.properties

来源: 未知 分享至:
http://www.blogjava.net/wmcoo/articles/333345.html

<?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

Tags:
分享至:
最新图文资讯
1 2 3 4 5 6
验证码:点击我更换图片 理智评论文明上网,拒绝恶意谩骂 用户名:
关于我们 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 发展历史