频道栏目
IT货架 > > 正文
SpringMVC-spring-hibernate配置有关问题
网友分享于:Jun 12, 2018 10:50:44 PM    来源: IT货架   
SpringMVC-spring-hibernate配置问题
 
web.xml的配置问题

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

   <servlet>
        <servlet-name>dispatcherServlet</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/hib-config.xml,/WEB-INF/web-config.xml,/WEB-INF/service-config.xml,/WEB-INF/dao-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
</web-app>



controller层的配置 web-config.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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<!-- Controller方法调用规则定义 -->
<bean id="paraMethodResolver"
class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
<property name="paramName" value="action" />
<property name="defaultMethodName" value="list" />
</bean>

<!-- 页面View层基本信息设定 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<!--<property name="prefix" value="/myjsp/"/>-->
<property name="suffix" value=".jsp" />
</bean>

<!-- servlet映射列表,所有控制层Controller的servlet在这里定义 -->
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="user.do">userController</prop>
</props>
</property>
</bean>

<bean id="userController" class="com.sxt.action.UserController">
<property name="userService" ref="userService"></property>
</bean>
</beans>


hibernate的配置文件 hib-config.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: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>






这段配置数据源的配置代码 是配置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>









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.x
------解决方案--------------------
到本地Oracle数据库文件夹db_1/NETWORK/ADMIN/listener.ora 改写一下监听文件 和 tnsnames的文件

广告服务联系QQ:1134687142 | 网站地图

版权所有: IT货架- 内容来自互联网,仅供用于技术学习,请遵循相关法律法规. 京ICP备11030978号-1