Mybatis-Spring icon indicating copy to clipboard operation
Mybatis-Spring copied to clipboard

config.properties 修改

Open jking8866 opened this issue 9 years ago • 9 comments

config.properties文件中,最后一行

mapper.Mapper = tk.mybatis.mapper.common.Mapper

是否应改为:

mapper.Mapper = com.isea533.mybatis.util.UtilMapper

原因是,用原来的配置,会导致生成的mapper包中接口继承有问题,不修改直接启项目会报错

启动报错后,查了好久才发现是这个问题

jking8866 avatar Jan 05 '17 16:01 jking8866

这行配置只在 generatorConfig.xml 中用到了。

abel533 avatar Jan 06 '17 14:01 abel533

如果不修改的话,启动服务会报错

jking8866 avatar Jan 07 '17 15:01 jking8866

报什么错?

abel533 avatar Jan 08 '17 13:01 abel533

一月 09, 2017 11:57:57 下午 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dishService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected tk.mybatis.mapper.common.Mapper org.orange.wenhe.service.impl.BaseService.mapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [tk.mybatis.mapper.common.Mapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1204)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4842)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5303)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected tk.mybatis.mapper.common.Mapper org.orange.wenhe.service.impl.BaseService.mapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [tk.mybatis.mapper.common.Mapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:555)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
	... 22 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [tk.mybatis.mapper.common.Mapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1308)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1054)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:527)
	... 24 more

一月 09, 2017 11:57:57 下午 org.apache.catalina.core.StandardContext startInternal
严重: One or more listeners failed to start. Full details will be found in the appropriate container log file
一月 09, 2017 11:57:57 下午 org.apache.catalina.core.StandardContext startInternal
严重: Context [/orange] startup failed due to previous errors
一月 09, 2017 11:57:57 下午 org.apache.catalina.core.ApplicationContext log
信息: Closing Spring root WebApplicationContext
一月 09, 2017 11:57:57 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
警告: The web application [orange] registered the JDBC driver [com.alibaba.druid.proxy.DruidDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
一月 09, 2017 11:57:57 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
警告: The web application [orange] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
一月 09, 2017 11:57:57 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
警告: The web application [orange] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
 com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:40)
一月 09, 2017 11:57:57 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-nio-7080"]
一月 09, 2017 11:57:57 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-nio-7009"]
一月 09, 2017 11:57:57 下午 org.apache.catalina.startup.Catalina start
信息: Server startup in 6658 ms

jking8866 avatar Jan 09 '17 15:01 jking8866

在命令行中使用generator,生成代码后,在mapper接口中继承的是Mapper,应继承MyMapper, 修改config.properties中的mapper.Mapper,才能正常启动,

jking8866 avatar Jan 09 '17 16:01 jking8866

generator 用了 mapper.Mapper 属性。。所以你改的对。

abel533 avatar Jan 10 '17 14:01 abel533

我也入坑(遇到这个问题) 查起来还挺费劲

还有另一种处理办法: spring-context.xml,更新markerInterface值为tk.mybatis.mapper.common.Mapper

<!-- @MyBatisDao注解的接口(Mapper<Entity>类支持) -->
<bean id="mapperScannerConfigurer" class="tk.mybatis.spring.mapper.MapperScannerConfigurer">
   <property name="markerInterface" value="tk.mybatis.mapper.common.Mapper"/>

建议: 为同在学习和使用Mybatis-Spring的同学们,少入一点坑。建议项目源码调整markerInterface默认值。 让使用过程更顺利,更灵活的能力可通过注释和文档进一步引导

liuxiang avatar Mar 18 '17 10:03 liuxiang

config.properties 注释显示数据库连接池你是用的c3p0么,不是druid么?

zhanghaichang avatar May 27 '17 01:05 zhanghaichang

@zhanghaichang 看这个:https://github.com/abel533/Mybatis-Spring/blob/master/src/main/resources/applicationContext.xml

abel533 avatar May 30 '17 04:05 abel533