数据库配置,基于JDNI

来源:互联网 发布:js输入框旁边提示信息 编辑:程序博客网 时间:2024/05/29 02:51

数据库配置无非分为两种,一种基于JNDI方式,一种非JDNC(jdbc)

  • JDNI方式
    server.xml:

    <Context   docBase="F:\IDE\workspaces\heipworkspace\cms\WebContent" path="/cms" privileged="true"><Resource name="jdbc/cms"   auth="Container" type="javax.sql.DataSource" username="cmsadmin"  password="123456"  maxActive="4" maxIdle="2" maxWait="5000"  url="jdbc:oracle:thin:@127.0.0.1:1521:ORCL" driverClassName="oracle.jdbc.driver.OracleDriver"/></Context>

    注意: 连接数据库的jar一定要放到tomcat里面。

    web.xml配置:

    <resource-ref id="ResourceRef_1">            <res-ref-name>jdbc/itms</res-ref-name>            <res-type>javax.sql.DataSource</res-type>            <res-auth>Container</res-auth></resource-ref>

    applicationContent.xml配置:

    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"><property name="resourceRef" value="true"/><property name="jndiName" value="jdbc/itms"/></bean>
  • 非JDNI方式

    JDBC配置

    jdbc.driverClassName=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/ssojdbc.username=rootjdbc.password=tiger

    applicationContent.xml配置

    <!-- 使用pproperties来配置DB属性 --><beanclass="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="locations"><value>classpath:jdbc.properties</value></property></bean><!-- 配置数据源属性 --><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"destroy-method="close"><property name="driverClassName" value="${jdbc.driverClassName}"></property><property name="url" value="${jdbc.url}"></property><property name="username" value="${jdbc.username}"></property><property name="password" value="${jdbc.password}"></property></bean>
0 0
原创粉丝点击