4-7spring配置问题

来源:4-7 Spring事务处理-基于tx命名空间

tryl

2018-12-10 21:38:00

警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext1.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException

十二月 10, 2018 9:23:00 下午 org.springframework.test.context.TestContextManager prepareTestInstance

严重: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@7f63425a] to prepare test instance [com.imooc.os.service.impl2.OrderTest@27ce24aa]

java.lang.IllegalStateException: Failed to load ApplicationContext

老师这样的错误是怎么回事啊


写回答

2回答

好帮手慕阿莹

2018-12-11

同学的数据库是哪个版本的呢?

1、如果是8.0版本的,同学的数据库驱动写的不对。

2、在xml中,url中的&符号要用 & 来代替。

3、检查一下你的数据库驱动是否和数据库版本一致呢?

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

0

tryl

提问者

2018-12-10

以下是我的spring-service4.xml的配置

<!--导入依赖的配置文件-->
<import resource="applicationContext1.xml"/>
<context:component-scan base-package="com.imooc.os.service.impl2"/>

<!--配置事务管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
   <property name="dataSource" ref="dataSource"/>
</bean>
<!--事务管理器,拦截器被封装在底层-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
   <tx:attributes>
       <tx:method name="get*" propagation="REQUIRED" read-only="true"/>
       <tx:method name="find*" propagation="REQUIRED" read-only="true"/>
       <tx:method name="search*" propagation="REQUIRED" read-only="true"/>
       <tx:method name="*" propagation="REQUIRED"/>
   </tx:attributes>
</tx:advice>
<aop:config>
   <!--切入点-->
   <!--第一个* 代表返回值;第二个* 代表所有类;第三个* 代表所有方法 -->
   <aop:pointcut id="pointcut" expression="execution(* com.imooc.os.service.impl2.*.*(..))"/>
   <!--为切入点配置事务管理器-->
   <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut"/>
</aop:config>

applicationContext1.xml的配置

<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/os?useUnicode=true&amp;characterEncoding=UTF-8"/>
   <property name="username" value="root"/>
   <property name="password" value="root"/>
</bean>

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
   <property name="dataSource" ref="dataSource"/>
</bean>

<context:component-scan base-package="com.imooc.os.dao"/>

0

0 学习 · 4317 问题

查看课程