美文网首页
2018-08-23

2018-08-23

作者: 城铠唐 | 来源:发表于2018-08-24 14:11 被阅读0次

    <code>

    package com.zhidisoft.config;

    import java.beans.PropertyVetoException;

    import javax.sql.DataSource;

    import org.springframework.beans.factory.annotation.Autowired;

    import org.springframework.context.annotation.Bean;

    import org.springframework.context.annotation.Configuration;

    import org.springframework.context.annotation.PropertySource;

    import org.springframework.core.env.Environment;

    import com.mchange.v2.c3p0.ComboPooledDataSource;

    //当前类是配置类 ,可以当做是配置文件

    @Configuration   

    //将properties文件引入到配置类中

    @PropertySource(value="classpath:jdbc.properties") 

    public class SpringConfig {

        @Bean

        public DataSource dataSource(@Autowired Environment env) throws PropertyVetoException{

            ComboPooledDataSource source = new ComboPooledDataSource();

            source.setDriverClass(env.getProperty("jdbc.mysql.driver"));

            source.setJdbcUrl(env.getProperty("jdbc.mysql.url"));

            source.setUser(env.getProperty("jdbc.mysql.user"));

            source.setPassword(env.getProperty("jdbc.mysql.password"));

            source.setMaxPoolSize(10);

            source.setMinPoolSize(5);

            source.setInitialPoolSize(6);

            source.setMaxConnectionAge(28800);

            source.setMaxIdleTime(21600);

            return source;

        }

    }

    </code>

    相关文章

      网友评论

          本文标题:2018-08-23

          本文链接:https://www.haomeiwen.com/subject/gngmiftx.html