日期:2014-05-17  浏览次数:20718 次

hibernate4.0+spring3.1+struts2.2.3集成无法访问数据库
hibernate4.0+spring3.1+struts2.2.3集成问题,数据库是mysql,hibernate.cfg.xml相同,直接用hibernate导出表访问数据库没有问题,但用spring管理去访问数据库却出现access denies 问题。用户名和密码肯定是没有错的。
下面是我的配置文件:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
  <property name="url" value="jdbc:mysql://localhost:3306/oa"/>
  <property name="username" value="root"/>
  <property name="password" value="5589"/>
  </bean>
  <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" scope="prototype">
  <property name="dataSource" ref="dataSource"/>
 
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>interview/test/bean/Person.hbm.xml</value>
</list>
</property>
</bean>
 
<!-- 
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" scope="prototype">
  <property name="configLocation">
  <value>classpath:hibernate.cfg.xml</value>
  </property>  
 
  </bean> -->
  <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
  <property name="sessionFactory">
  <ref bean="sessionFactory"/>
  </property>
  </bean>
  <tx:advice id="advice" transaction-manager="transactionManager">
  <tx:attributes>
  <tx:method name="add*" propagation="REQUIRED"/>
  <tx:method name="delete*" propagation="REQUIRED"/>
  <tx:method name="update*" propagation="REQUIRED"/>
  <tx:method name="*" read-only="true"/>
  </tx:attributes>
  </tx:advice>
  <aop:config>
  <aop:pointcut expression="execution(* interview.test.beanmanager.*.*(..))" id="allmethod"/>
  <aop:advisor pointcut-ref="allmethod" advice-ref="advice"/>
  </aop:config>
 
 
  <!-- <bean id="beanManager" class="test.spring.BeanManagerImpl"/>
  <bean id="security" class="test.spring.CheckSecurity"/>
  
   
  <aop:config>
  <aop:aspect id="securityHandler" ref="security">
  <aop:pointcut id="allAddMethod" expression="execution(* add*(..))"/>
  <aop:before method="checkSecurity" pointcut-ref="allAddMethod"/>
  </aop:aspect>
   
  </aop:config>