运行时报错,这是什么原因?
报如下错:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [spring.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': Cannot resolve reference to bean 'txPointcut' while setting bean property 'pointcut'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'txPointcut': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.aop.aspectj.AspectJExpressionPointcut] from ClassLoader [WebappClassLoader
context: /sm
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
java.net.URLClassLoader@6e5e91e4
]
spring.xml的代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | <? 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:context = "http://www.springframework.org/schema/context" xmlns:aop = "http://www.springframework.org/schema/aop" xmlns:tx = "http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!--Spring整合Mybatis--> <!--数据源--> < 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/sm?useUnicode=true&characterEncoding=utf-8" /> < property name = "username" value = "root" /> < property name = "password" value = "root" /> </ bean > <!--配置sqlSessionFactory,这个类来自于mybatis和spring整合包--> < bean id = "sqlSessionFactory" class = "org.mybatis.spring.SqlSessionFactoryBean" > < property name = "dataSource" ref = "dataSource" /> <!--指定一个包,这包里面的所有类都可以直接用简称的方式(直接用类名,不加包名)来调用--> < property name = "typeAliasesPackage" value = "com.yuan.sm.entity" /> </ bean > <!--mybatis提供一个非常实用的功能:自动映射--> <!--作用:你给我指定一个包,在这个包里面放置对应的持久化操作接口和映射文件,我会把这个包里面的所有的接口全部整合起来,然后实现相应的功能--> < bean class = "org.mybatis.spring.mapper.MapperScannerConfigurer" > < property name = "basePackage" value = "com.yuan.sm.dao" /> < property name = "sqlSessionFactoryBeanName" value = "sqlSessionFactory" /> </ bean > <!--声明式事务--> <!--事务管理器--> < 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*" read-only = "true" /> < tx:method name = "find*" read-only = "true" /> < tx:method name = "search*" read-only = "true" /> <!--如果是其他方法(如增删改),则必须使用事务--> < tx:method name = "*" propagation = "REQUIRED" /> </ tx:attributes > </ tx:advice > <!--织入--> < aop:config > < aop:pointcut id = "txPointcut" expression = "execution(* com.yuan.sm.service.*.*(..))" /> < aop:advisor advice-ref = "txAdvice" pointcut-ref = "txPointcut" /> </ aop:config > <!--开启全局扫描--> < context:component-scan base-package = "com.yuan.sm" /> <!--打开aspectj的自动代理--> < aop:aspectj-autoproxy /> </ beans > |
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 205 份
- 解答问题 4317 个
Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧