java吧 关注:1,294,631贴子:12,827,741
  • 5回复贴,共1

SSH 配置数据源问题

只看楼主收藏回复

RT


1楼2013-04-11 09:35回复
    hib-config.xml
    的配置是这样的


    2楼2013-04-11 09:35
    回复
      2026-01-15 07:01:37
      广告
      不感兴趣
      开通SVIP免广告
      <?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:aop="http://www.springframework.org/schema/aop"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
      http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-2.5.xsd
      ">
      <context:component-scan base-package="com.sxt"/>
      <!-- 支持aop注解 -->
      <aop:aspectj-autoproxy />
      <bean id="dataSource"
      class="org.apache.commons.dbcp.BasicDataSource">
      <property name="driverClassName"
      value="oracle.jabc.driver.OracleDriver">
      </property>
      <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:springmvc"></property>
      <property name="username" value="springmvc"></property>
      <property name="password" value="springmvc"></property>
      </bean>
      <bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      <property name="dataSource">
      <ref bean="dataSource" />
      </property>
      <property name="hibernateProperties">
      <props>
      <!-- key的名字前面都要加hibernate. -->
      <prop key="hibernate.dialect">
      <!-- org.hibernate.dialect.MySQLDialect -->
      org.hibernate.dialect.Oracle9iDialect
      </prop>
      <prop key="hibernate.show_sql">true</prop>
      <prop key="hibernate.hbm2ddl.auto">update</prop>
      </props>
      </property>
      <property name="packagesToScan">
      <value>com.sxt.model</value>
      </property>
      </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate" >
      <property name="sessionFactory" ref="sessionFactory"></property>
      </bean> <!--配置一个JdbcTemplate实例-->
      <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
      <property name="dataSource" ref="dataSource"/>
      </bean>
      <!-- 配置事务管理 -->
      <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
      <property name="sessionFactory" ref="sessionFactory"></property>
      </bean>
      <tx:annotation-driven transaction-manager="txManager" />
      <aop:config>
      <aop:pointcut expression="execution(public * com.sxt.service.impl.*.*(..))" id="businessService"/>
      <aop:advisor advice-ref="txAdvice" pointcut-ref="businessService" />
      </aop:config>
      <tx:advice id="txAdvice" transaction-manager="txManager" >
      <tx:attributes>
      <tx:method name="find*" read-only="true" propagation="NOT_SUPPORTED" />
      <!-- get开头的方法不需要在事务中运行 。
      有些情况是没有必要使用事务的,比如获取数据。开启事务本身对性能是有一定的影响的-->
      <tx:method name="*"/> <!-- 其他方法在实务中运行 -->
      </tx:attributes>
      </tx:advice> </beans>


      3楼2013-04-11 09:36
      回复
        这段配置数据源的配置代码 是配置Oracle 的
        <bean id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName"
        value="oracle.jabc.driver.OracleDriver">
        </property>
        <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:springmvc"></property>
        <property name="username" value="springmvc"></property>
        <property name="password" value="springmvc"></property>
        </bean>


        4楼2013-04-11 09:37
        回复
          org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in class path resource [spring-config.xml]: Could not resolve placeholder 'connection.driver_class' in string value [${connection.driver_class}]
          但是报错是这样的
          表示无法理解 我表示我没有 配置文件叫做 spring-config.xml


          5楼2013-04-11 09:40
          回复
            <property name="hibernateProperties">
            <props>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            <prop key="hibernate.format_sql">false</prop>
            <prop key="hibernate.query.substitutions">${hibernate.query.substitutions}</prop>
            <prop key="hibernate.default_batch_fetch_size">${hibernate.default_batch_fetch_size}</prop>
            <prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>
            <prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
            <prop key="hibernate.bytecode.use_reflection_optimizer">${hibernate.bytecode.use_reflection_optimizer}
            </prop>
            <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
            <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
            <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
            <prop key="net.sf.ehcache.configurationResourceName">${net.sf.ehcache.configurationResourceName}</prop>
            <prop key="hibernate.cache.use_structured_entries">${hibernate.cache.use_structured_entries}</prop>
            <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.SingletonEhCacheRegionFactory</prop>
            <prop key="hibernate.connection.url">jdbc:oracle:thin:@127.0.0.1:1521:sinojfs</prop>
            <prop key="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</prop>
            <prop key="hibernate.connection.username">sinojfs</prop>
            <prop key="hibernate.connection.password">sinojfs</prop>
            </props>
            </property>


            6楼2013-04-11 14:41
            回复