mybatis中SqlSessionFactoryBean路径配置错误

mybatis配置文件

Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.core.io.Resource[]' for property 'mapperLocations'; nested exception is java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:/com/**/wap/dao/impl/*.xml]: class path resource [com/***/wap/dao/impl/] cannot be resolved to URL because it does not exist

Caused by: java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:/com/***/wap/dao/impl/*.xml]: class path resource [com/***/wap/dao/impl/] cannot be resolved to URL because it does not exist



路径报错:修改为

<bean id="msqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
   <property name="dataSource" ref="dataSource" />
   <property name="mapperLocations" value="classpath*:/com/**/wap/dao/impl/*.xml" />
</bean>

http://ojdbc.com/springmvcmybatis-exception-resolution/

发布了194 篇原创文章 · 获赞 26 · 访问量 23万+
展开阅读全文

spring-mybatis找不到sqlsessionfactoryBean这个类

12-17

各位,我用maven管理项目,在pom.xml配置中导入了mybatis-spring 1.3.0.jar,![图片说明](https://img-ask.csdn.net/upload/201612/17/1481973764_854255.png) 然后在spring-mybatis.xml中配置了SqlSessionFactoryBean如下图:![图片说明](https://img-ask.csdn.net/upload/201612/17/1481973637_358834.png), 在任何类中使用sqlsessionFactoryBean这个类时eclipse不提示此类,如下图:![图片说明](https://img-ask.csdn.net/upload/201612/17/1481974113_834269.png) 当将类名输入完整后,再按Ctrl+1时又会有此类提示,如下图![图片说明](https://img-ask.csdn.net/upload/201612/17/1481974273_352542.png) 当用Junit测试时,如下图![图片说明](https://img-ask.csdn.net/upload/201612/17/1481974331_220161.png) 抛出classnotfindException: org.mybatis.spring.SqlSessionFactoryBean异常,异常信息如下: 严重: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@429bd883] to prepare test instance [business.test.Test@784c3487] java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.mybatis.spring.SqlSessionFactoryBean] for bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]; nested exception is java.lang.ClassNotFoundException: org.mybatis.spring.SqlSessionFactoryBean at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1361) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:639) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:607) at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1456) at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:983) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:734) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:108) at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:251) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116) ... 25 more Caused by: java.lang.ClassNotFoundException: org.mybatis.spring.SqlSessionFactoryBean at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at org.springframework.util.ClassUtils.forName(ClassUtils.java:250) at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:394) at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1408) at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1353) ... 38 more 求大神支招,谢谢各位 问答

求助Spring-boot Mybatis问题

01-22

单个Mapper都可以扫到,正常运行,就是两个放同一个目录下,就报错了,求解,下面是我的代码@Configuration @MapperScan(basePackages={"cn.com.bsfit.frms.ds.mapper"},sqlSessionFactoryRef="dsSqlSessionFactory") public class DsDataSourceConfig { @Bean @ConfigurationProperties(prefix = "frms.merchants.ds") public DataSource dsDataSource() { return DataSourceBuilder.create().build(); } @Bean public SqlSessionFactory dsSqlSessionFactory(@Qualifier("dsDataSource")DataSource dsDataSource) throws Exception { if (dsDataSource != null) { SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); bean.setDataSource(dsDataSource); bean.setConfigLocation(new ClassPathResource("DSMybatisConfig.xml")); return bean.getObject(); } return null; } @Bean public DataSourceTransactionManager dsTransactionManager(@Qualifier("dsDataSource")DataSource dsDataSource){ if(dsDataSource!=null) return new DataSourceTransactionManager(dsDataSource); return null; } @Bean public DSPayOrderMapper dsPayOrderMapper() throws Exception { SqlSessionTemplate sessionTemplate = new SqlSessionTemplate(dsSqlSessionFactory())); return sessionTemplate.getMapper(DSPayOrderMapper.class); } } 下面是错误信息 19:46:34.272 [main] WARN o.s.b.f.s.DefaultListableBeanFactory - Bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DSPayOrderMapper' defined in file [D:\WORK\eclipse-4.5\workspace\frms-merchant\target\classes\cn\com\bsfit\frms\ds\mapper\DSPayOrderMapper.class]: Cannot resolve reference to bean 'dsSqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'dsSqlSessionFactory': Requested bean is currently in creation: Is there an unresolvable circular reference? 19:46:34.388 [main] WARN o.s.b.f.s.DefaultListableBeanFactory - Bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DSPayOrderMapper' defined in file [D:\WORK\eclipse-4.5\workspace\frms-merchant\target\classes\cn\com\bsfit\frms\ds\mapper\DSPayOrderMapper.class]: Cannot resolve reference to bean 'dsSqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'dsSqlSessionFactory': Requested bean is currently in creation: Is there an unresolvable circular reference? 问答

关于mybatis引用mapper.xml文件的路径问题

01-02

我是看 https://www.cnblogs.com/xdp-gacl/p/4261895.html 的入门例子照着写的: 先是定义了User类,然后写一个conf.xml的myBatis配置文件,再写一个sql映射文件命名为userMapper.xml,最后再conf.xml中用resource标签引入userMapper.xml。 **但博客里是普通的java项目,路径引用我知道怎么写。而我创建的是maven-webapp项目,不知道怎么写路径地址了。** 项目结构如下: ![图片说明](https://img-ask.csdn.net/upload/201901/02/1546408643_318957.jpg) # 在mybatis-config.xml文件里添加了mapper,是这么引用的: <mapper resource="userMapper.xml"/> 能正常运行,但是有几个问题: - **1. 我看到网上说在src/main/resources下的xml文件,在配置文件里引用时,好面可以写上classpath,如:** <mapper resource="classpath:userMapper.xml"/> 但我试了,却找不到userMapper.xml。想请问下,classpath代表什么,是怎么用的呢? - **2. 同样写这句:** <mapper resource="userMapper.xml"/> 由于src/main/java 和 src/main/resources的output folder都是mybatis/target/classes,但我把userMapper.xml移到src/main/java下,运行却提示找不到userMapper.xml呢? - **3. 我现在是把mybatis-config.xml文件放在src/main/resources下,Test类中是这么写的资源地址:** String resource = “mybatis-config.xml”; 但如果我要把xml放到src/main/java下,要怎么写呢? **补充:** 求助各位,谢谢啦。 问答

Spring mvc+mybatis+maven的项目tomcat启动的时候,控制台不输出xml文件的加载信息

03-17

2014-3-17 9:52:18 org.apache.catalina.core.AprLifecycleListener init 信息: Loaded APR based Apache Tomcat Native library 1.1.24 using APR version 1.4.6. 2014-3-17 9:52:18 org.apache.catalina.core.AprLifecycleListener init 信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true]. 2014-3-17 9:52:18 org.apache.catalina.core.AprLifecycleListener initializeSSL 信息: OpenSSL successfully initialized (OpenSSL 1.0.1c 10 May 2012) 2014-3-17 9:52:19 org.apache.coyote.AbstractProtocol init 信息: Initializing ProtocolHandler ["http-apr-8080"] 2014-3-17 9:52:19 org.apache.coyote.AbstractProtocol init 信息: Initializing ProtocolHandler ["ajp-apr-8009"] 2014-3-17 9:52:19 org.apache.catalina.startup.Catalina load 信息: Initialization processed in 1944 ms 2014-3-17 9:52:19 org.apache.catalina.core.StandardService startInternal 信息: Starting service Catalina 2014-3-17 9:52:19 org.apache.catalina.core.StandardEngine startInternal 信息: Starting Servlet Engine: Apache Tomcat/7.0.32 2014-3-17 9:52:19 org.apache.catalina.startup.HostConfig deployDirectory 信息: Deploying web application directory D:\apache-tomcat-7.0.32\webapps\sso 2014-3-17 9:52:23 org.apache.catalina.core.ApplicationContext log 信息: Initializing Spring root WebApplicationContext log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader). log4j:WARN Please initialize the log4j system properly. 09:52:25.000 [localhost-startStop-1] DEBUG org.apache.ibatis.logging.LogFactory - Logging initialized using 'org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter. 09:52:26.250 [localhost-startStop-1] DEBUG o.m.spring.SqlSessionFactoryBean - Property 'configLocation' not specified, using default MyBatis Configuration 09:52:26.343 [localhost-startStop-1] DEBUG o.m.spring.SqlSessionFactoryBean - Property 'mapperLocations' was not specified or no matching resources found 09:52:26.734 [localhost-startStop-1] DEBUG net.sf.ehcache.CacheManager - Creating new CacheManager with default config 09:52:26.750 [localhost-startStop-1] DEBUG net.sf.ehcache.CacheManager - Configuring ehcache from classpath. 09:52:26.750 [localhost-startStop-1] WARN n.s.e.config.ConfigurationFactory - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/D:/apache-tomcat-7.0.32/webapps/sso/WEB-INF/lib/ehcache-core-2.4.3.jar!/ehcache-failsafe.xml 09:52:26.750 [localhost-startStop-1] DEBUG n.s.e.config.ConfigurationFactory - Configuring ehcache from URL: jar:file:/D:/apache-tomcat-7.0.32/webapps/sso/WEB-INF/lib/ehcache-core-2.4.3.jar!/ehcache-failsafe.xml 09:52:26.750 [localhost-startStop-1] DEBUG n.s.e.config.ConfigurationFactory - Configuring ehcache from InputStream 09:52:26.781 [localhost-startStop-1] DEBUG net.sf.ehcache.config.BeanHandler - Ignoring ehcache attribute xmlns:xsi 09:52:26.781 [localhost-startStop-1] DEBUG net.sf.ehcache.config.BeanHandler - Ignoring ehcache attribute xsi:noNamespaceSchemaLocation 09:52:26.781 [localhost-startStop-1] DEBUG n.s.e.config.DiskStoreConfiguration - Disk Store Path: D:\apache-tomcat-7.0.32\temp 09:52:26.843 [localhost-startStop-1] DEBUG net.sf.ehcache.util.PropertyUtil - propertiesString is null. 09:52:26.843 [localhost-startStop-1] DEBUG n.s.e.config.ConfigurationHelper - No CacheManagerEventListenerFactory class specified. Skipping... 09:52:26.921 [localhost-startStop-1] DEBUG net.sf.ehcache.Cache - No BootstrapCacheLoaderFactory class specified. Skipping... 09:52:26.921 [localhost-startStop-1] DEBUG net.sf.ehcache.Cache - CacheWriter factory not configured. Skipping... 09:52:26.921 [localhost-startStop-1] DEBUG n.s.e.config.ConfigurationHelper - No CacheExceptionHandlerFactory class specified. Skipping... 09:52:26.968 [localhost-startStop-1] DEBUG n.s.e.s.c.f.DiskOverflowStorageFactory - Deleting data file com.ustl.gd.droit.daoImpl.DroitDao.data 09:52:27.000 [localhost-startStop-1] DEBUG net.sf.ehcache.Cache - Initialised cache: com.ustl.gd.droit.daoImpl.DroitDao 09:52:27.000 [localhost-startStop-1] DEBUG n.s.e.config.ConfigurationHelper - CacheDecoratorFactory not configured for defaultCache. Skipping for 'com.ustl.gd.droit.daoImpl.DroitDao'. 09:52:27.109 [localhost-startStop-1] DEBUG n.s.e.s.c.f.DiskOverflowStorageFactory - Deleting data file com.ustl.gd.rtd.daoImpl.RtdDao.data 09:52:27.109 [localhost-startStop-1] DEBUG net.sf.ehcache.Cache - Initialised cache: com.ustl.gd.rtd.daoImpl.RtdDao 09:52:27.109 [localhost-startStop-1] DEBUG n.s.e.config.ConfigurationHelper - CacheDecoratorFactory not configured for defaultCache. Skipping for 'com.ustl.gd.rtd.daoImpl.RtdDao'. 09:52:27.125 [localhost-startStop-1] DEBUG n.s.e.s.c.f.DiskOverflowStorageFactory - Deleting data file com.ustl.gd.utr.daoImpl.UtrDao.data 09:52:27.125 [localhost-startStop-1] DEBUG net.sf.ehcache.Cache - Initialised cache: com.ustl.gd.utr.daoImpl.UtrDao 09:52:27.125 [localhost-startStop-1] DEBUG n.s.e.config.ConfigurationHelper - CacheDecoratorFactory not configured for defaultCache. Skipping for 'com.ustl.gd.utr.daoImpl.UtrDao'. 09:52:27.156 [localhost-startStop-1] DEBUG n.s.e.s.c.f.DiskOverflowStorageFactory - Deleting data file com.ustl.gd.user.daoImpl.UserDao.data 09:52:27.156 [localhost-startStop-1] DEBUG net.sf.ehcache.Cache - Initialised cache: com.ustl.gd.user.daoImpl.UserDao 09:52:27.156 [localhost-startStop-1] DEBUG n.s.e.config.ConfigurationHelper - CacheDecoratorFactory not configured for defaultCache. Skipping for 'com.ustl.gd.user.daoImpl.UserDao'. 09:52:27.171 [localhost-startStop-1] DEBUG n.s.e.s.c.f.DiskOverflowStorageFactory - Deleting data file com.ustl.gd.role.daoImpl.RoleDao.data 09:52:27.171 [localhost-startStop-1] DEBUG net.sf.ehcache.Cache - Initialised cache: com.ustl.gd.role.daoImpl.RoleDao 09:52:27.171 [localhost-startStop-1] DEBUG n.s.e.config.ConfigurationHelper - CacheDecoratorFactory not configured for defaultCache. Skipping for 'com.ustl.gd.role.daoImpl.RoleDao'. 2014-3-17 9:52:27 org.apache.catalina.core.ApplicationContext log 信息: Initializing Spring FrameworkServlet 'spring-mvc' 09:52:27.937 [net.sf.ehcache.CacheManager@30a895] DEBUG net.sf.ehcache.util.UpdateChecker - Checking for update... 2014-3-17 9:52:29 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["http-apr-8080"] 2014-3-17 9:52:29 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["ajp-apr-8009"] 2014-3-17 9:52:29 org.apache.catalina.startup.Catalina start 信息: Server startup in 9622 ms 09:52:31.234 [net.sf.ehcache.CacheManager@30a895] DEBUG net.sf.ehcache.util.UpdateChecker - Update check failed: java.net.SocketTimeoutException: connect timed out 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览