Closed kaixinwangzi1982 closed 8 years ago
I write some codes in samples . errors comes
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'areaDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected org.apache.ibatis.session.SqlSession sample.mybatis.BaseDao.writableSQLSession; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.apache.ibatis.session.SqlSession] 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), @org.springframework.beans.factory.annotation.Qualifier(value=writableSQLSession)} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE] at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE] at sample.mybatis.SampleMapperApplication.main(SampleMapperApplication.java:38) [classes/:na] Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected org.apache.ibatis.session.SqlSession sample.mybatis.BaseDao.writableSQLSession; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.apache.ibatis.session.SqlSession] 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), @org.springframework.beans.factory.annotation.Qualifier(value=writableSQLSession)} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] ... 16 common frames omitted Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.apache.ibatis.session.SqlSession] 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), @org.springframework.beans.factory.annotation.Qualifier(value=writableSQLSession)} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] ... 18 common frames omitted
my dao @Component public class AreaDao extends BaseDao {
@Autowired
AreaMapper areaMapper;
public Area findById(int id) {
areaMapper = readonlySQLSession.getMapper(AreaMapper.class);
return areaMapper.selectByPrimaryKey(id);
}
public List<Area> queryParents() {
// return findByProperty("pid",0); areaMapper = readonlySQLSession.getMapper(AreaMapper.class); AreaExample example = new AreaExample(); Criteria c = example.createCriteria(); c.andPidEqualTo(0); return areaMapper.selectByExample(example); }
public List<Area> queryChildrenByPid(int pid) {
// String hql = "from Area model where model.pid=?"; // List list = (List) getHibernateTemplate().find(hql, pid); areaMapper = readonlySQLSession.getMapper(AreaMapper.class); AreaExample example = new AreaExample(); Criteria c = example.createCriteria(); c.andPidEqualTo(pid); return areaMapper.selectByExample(example); } }
BaseDao is
package sample.mybatis;
import org.apache.ibatis.session.SqlSession; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier;
public class BaseDao {
/**
* 可写的sqlSession
*/
@Autowired
@Qualifier("writableSQLSession")
protected SqlSession writableSQLSession;
/**
* 只读的sqlSession
*/
@Autowired
@Qualifier("writableSQLSession")
protected SqlSession readonlySQLSession;
public SqlSession getWritableSQLSession() {
return writableSQLSession;
}
public SqlSession getReadonlySQLSession() {
return readonlySQLSession;
}
public void setWritableSQLSession(SqlSession writableSQLSession) {
this.writableSQLSession = writableSQLSession;
}
public void setReadonlySQLSession(SqlSession readonlySQLSession) {
this.readonlySQLSession = readonlySQLSession;
}
}
Sorry but this bug is not related with spring boot. Is it?
I followed the samples and create a new boot project and run it. errors displayed in console.
java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class org.mybatis.spring.annotation.MapperScan.factoryBean() at java.lang.reflect.Method.getDefaultValue(Method.java:747) ~[na:1.7.0_80] at sun.reflect.annotation.AnnotationType.(AnnotationType.java:128) ~[na:1.7.0_80]
at sun.reflect.annotation.AnnotationType.getInstance(AnnotationType.java:85) ~[na:1.7.0_80]
at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:263) ~[na:1.7.0_80]
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:117) ~[na:1.7.0_80]
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:70) ~[na:1.7.0_80]
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3281) ~[na:1.7.0_80]
at java.lang.Class.getDeclaredAnnotations(Class.java:3258) ~[na:1.7.0_80]
at org.springframework.core.annotation.AnnotationUtils.findAnnotation(AnnotationUtils.java:704) ~[spring-core-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.core.annotation.AnnotationUtils.findAnnotation(AnnotationUtils.java:683) ~[spring-core-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.core.annotation.AnnotationUtils.findAnnotation(AnnotationUtils.java:660) ~[spring-core-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.boot.BeanDefinitionLoader.isComponent(BeanDefinitionLoader.java:266) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:157) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:134) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:126) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.load(SpringApplication.java:708) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:357) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at com.pms.SampleMapperApplication.main(SampleMapperApplication.java:38) [classes/:na]
2016-05-07 23:25:32.572 INFO 6300 --- [ main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/D:/Workspace/pms-refresher/target/classes/, file:/G:/env/resp/org/springframework/boot/spring-boot-starter/1.3.3.RELEASE/spring-boot-starter-1.3.3.RELEASE.jar, file:/G:/env/resp/org/springframework/boot/spring-boot/1.3.3.RELEASE/spring-boot-1.3.3.RELEASE.jar, file:/G:/env/resp/org/springframework/spring-context/4.2.5.RELEASE/spring-context-4.2.5.RELEASE.jar, file:/G:/env/resp/org/springframework/spring-aop/4.2.5.RELEASE/spring-aop-4.2.5.RELEASE.jar, file:/G:/env/resp/aopalliance/aopalliance/1.0/aopalliance-1.0.jar, file:/G:/env/resp/org/springframework/spring-beans/4.2.5.RELEASE/spring-beans-4.2.5.RELEASE.jar, file:/G:/env/resp/org/springframework/spring-expression/4.2.5.RELEASE/spring-expression-4.2.5.RELEASE.jar, file:/G:/env/resp/org/springframework/boot/spring-boot-autoconfigure/1.3.3.RELEASE/spring-boot-autoconfigure-1.3.3.RELEASE.jar, file:/G:/env/resp/org/springframework/boot/spring-boot-starter-logging/1.3.3.RELEASE/spring-boot-starter-logging-1.3.3.RELEASE.jar, file:/G:/env/resp/ch/qos/logback/logback-classic/1.1.5/logback-classic-1.1.5.jar, file:/G:/env/resp/ch/qos/logback/logback-core/1.1.5/logback-core-1.1.5.jar, file:/G:/env/resp/org/slf4j/slf4j-api/1.7.16/slf4j-api-1.7.16.jar, file:/G:/env/resp/org/slf4j/jcl-over-slf4j/1.7.16/jcl-over-slf4j-1.7.16.jar, file:/G:/env/resp/org/slf4j/jul-to-slf4j/1.7.16/jul-to-slf4j-1.7.16.jar, file:/G:/env/resp/org/slf4j/log4j-over-slf4j/1.7.16/log4j-over-slf4j-1.7.16.jar, file:/G:/env/resp/org/springframework/spring-core/4.2.5.RELEASE/spring-core-4.2.5.RELEASE.jar, file:/G:/env/resp/org/yaml/snakeyaml/1.16/snakeyaml-1.16.jar, file:/G:/env/resp/org/mybatis/mybatis/3.4.0/mybatis-3.4.0.jar, file:/G:/env/resp/org/mybatis/mybatis-spring/1.3.0/mybatis-spring-1.3.0.jar]
and pom.xml :+1:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">