Tag Archives: mybatis

Remember a mybatis error org.apache.ibatis . session.defaults.DefaultSqlSession

Today, MyBatis was used to insert a hop record into the database, and the error was reported as follows:
SqlSession [org. Apache. Ibatis. Session. Defaults. DefaultSqlSession @ 74794994] was not registered for synchronization because synchronization is not active
The error is due to the fact that one of my fields is NULL, but the database design, this field cannot be NULL, so the error is to change the input field not NULL, to solve the error.
Welcome to pay attention to my public number, learn together, exchange.

 

[solved] closingontransa ctionalSqlSessionorg.apache.ibatis . session.defaults.DefaultSqlSession @20] No information after that.

Today in learning to follow the teacher learning Mybatis – plus technology found god in the use of the test class testing to add and delete operation, display Closing non transactional SqlSession [org. Apache. Ibatis. Session. Defaults. DefaultSqlSession @ 656922 a0] after no information feedback, no results after searching for some information.

The solution
Eventually find the main class does not start: @ MapperScan (com. Kuang. "mapper")
pay attention to the point, we need to start class up to scan our mapper package of all interface

to add @ MapperScan (" com. Kuang. Mapper ") scans we mapper under UserMapper interface inheritance parent class BaseMapper< User> . In order to identify all methods in the parent class.

import org.mybatis.spring.annotation.MapperScan;
@MapperScan("com.kuang.mapper")

Then test the class again and find that the data is present and the information is fed back.

Using greater than sign or less than sign to report error in mybatis

Problem Description: Using <; = will prompt an error Tag name Expecte

tee.F_EndDay <= dateadd(DAY,0,CONVERT (VARCHAR(100), GETDATE(), 23))

1, will be < Number or & gt; The number is escaped

tee.F_EndDay &lt;= dateadd(DAY,0,CONVERT (VARCHAR(100), GETDATE(), 23))

2. Use lt; ! [CDATA[ ]]> Symbol description

<![CDATA[ tee.F_EndDay &lt;= dateadd(DAY,0,CONVERT (VARCHAR(100), GETDATE(), 23)) ]]>  

Appendix escape comparison table

The

& amp; lt;

& lt; No.

<

& amp; gt;

& gt;

is greater than the number

& amp; amp;

& amp;

and

& amp; apos;

single quotes

& amp; quot;

double quotation marks

Configuration error in mybatis configuration file

Development in mybatis mybatis project – config. After adding elements in the XML, found in the XML configuration label error: before and after the content for an error & lt; properties& gt; settings& gt; typeAliases& gt; typeHandlers& gt; objectFactory& gt; objectWrapperFactory& . >
Then find the answer in a development tool:
& lt; configuration> The child elements of the must follow: <<; properties> & lt; settings> & lt; typeAliases> & lt; typeHandlers> & lt; objectFactory> & lt; plugins>                                                                                                                                  & lt; enviroments>      & lt; databaseIdProvider>                                                               & lt; mappers>   In that order. Otherwise, MyBatis will report an error when parsing XML.

Mybatis single parameter pass in exception (How to Fix)

MyBatis passes in an exception for a single parameter

Integer or java.lang.String, if we do not perform dynamic SQL splicing, it will not report an error, when performing dynamic splicing, it will report an error, the error is as follows

Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'rname' in 'class java.lang.String'
### Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'rname' in 'class java.lang.String'

1. Interface code

 int selectCount(String rname);

2. Configuration file code

  <select id="selectCount" resultType="int" parameterType="string">
        select count(*) from cst_customer where 1=1
        <if test="rname!=null and rname!=''">
        and cust_name like #{rname}
        </if>
    </select>

3. How to solve it

   <select id="selectCount" resultType="int" parameterType="string">
        select count(*) from cst_customer where 1=1
        <if test="_parameter!=null and _parameter!=''">
        and cust_name like #{rname}
        </if>
    </select>

4. Why are errors reported

When passing a single parameter to dynamically splice sql, mybatis converts our parameter to _parameter by default, or you can add the @Param comment to the interface field.

Mybatis batch insert data

Due to the project need to generate more data, and saved to the database, in the program encapsulates a List collection objects, then need to put the collection of entities in the inserted into the database, the project USES the Spring + MyBatis, therefore intends to use the MyBatis bulk insert, should be better than that of circular insert, because before used bulk insert, finally achieved after got some information on the Internet, stick process in detail. For future reference and study.
Java code:

Java code:

Error when connecting to database: DB2 SQL error: sqlcode = – 204, sqlstate = 42704, sqlerrmc= YXUAT.CUST_ BLK_ REL, DRIVER=4.25.13

DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC= yxuat. CUST_BLK_REL, DRIVER=4.25.13

Reason: When using MyBATIS, the remote database was connected, and the login user did not specify which schemas to use, that is, the user name was not specified. This led to the fact that Mybaits could not find the schemas we wanted, so it reported an error.
Solution 1: When you write SQL statements, you simply add schemas before the table names in the SQL
For example: SELECT * from cmis_uat1.cust_blk_rel
Solution 2: Add schemas when configuring datasource.
For example: spring: a datasource: url: JDBC: db2:// 10.10.0.36:50000/HNCKC: currentSchema = CMIS_UAT1; username: yxuat password: xfjr2016

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name

The following is the problem of Springboot+ MybATIS project, the specific error message is as follows:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customMetadataSource': Unsatisfied dependency expressed through field 'menuService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'menuService': Unsatisfied dependency expressed through field 'menuMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'menuMapper' defined in file [D:\workspace-sts-3.9.9.RELEASE\springboot-vhr\target\classes\com\chinamobile\cmss\mapper\MenuMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.io.FileNotFoundException: class path resource [mybatis-config.xml] cannot be opened because it does not exist
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:374) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1411) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
	at com.chinamobile.cmss.SpringbootVhrApplication.main(SpringbootVhrApplication.java:14) [classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_211]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_211]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_211]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_211]
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.1.8.RELEASE.jar:2.1.8.RELEASE]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'menuService': Unsatisfied dependency expressed through field 'menuMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'menuMapper' defined in file [D:\workspace-sts-3.9.9.RELEASE\springboot-vhr\target\classes\com\chinamobile\cmss\mapper\MenuMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.io.FileNotFoundException: class path resource [mybatis-config.xml] cannot be opened because it does not exist
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:374) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1411) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1251) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1171) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:593) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	... 24 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'menuMapper' defined in file [D:\workspace-sts-3.9.9.RELEASE\springboot-vhr\target\classes\com\chinamobile\cmss\mapper\MenuMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.io.FileNotFoundException: class path resource [mybatis-config.xml] cannot be opened because it does not exist
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1515) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1395) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1251) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1171) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:593) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	... 37 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.io.FileNotFoundException: class path resource [mybatis-config.xml] cannot be opened because it does not exist
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:607) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1251) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1171) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1500) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	... 48 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.io.FileNotFoundException: class path resource [mybatis-config.xml] cannot be opened because it does not exist
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	... 61 common frames omitted
Caused by: java.io.FileNotFoundException: class path resource [mybatis-config.xml] cannot be opened because it does not exist
	at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:406) ~[mybatis-spring-1.3.2.jar:1.3.2]
	at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:380) ~[mybatis-spring-1.3.2.jar:1.3.2]
	at org.mybatis.spring.SqlSessionFactoryBean.getObject(SqlSessionFactoryBean.java:547) ~[mybatis-spring-1.3.2.jar:1.3.2]
	at org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration.sqlSessionFactory(MybatisAutoConfiguration.java:153) ~[mybatis-spring-boot-autoconfigure-1.3.2.jar:1.3.2]
	at org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration$$EnhancerBySpringCGLIB$$2af73e32.CGLIB$sqlSessionFactory$0(<generated>) ~[mybatis-spring-boot-autoconfigure-1.3.2.jar:1.3.2]
	at org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration$$EnhancerBySpringCGLIB$$2af73e32$$FastClassBySpringCGLIB$$d55079df.invoke(<generated>) ~[mybatis-spring-boot-autoconfigure-1.3.2.jar:1.3.2]
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration$$EnhancerBySpringCGLIB$$2af73e32.sqlSessionFactory(<generated>) ~[mybatis-spring-boot-autoconfigure-1.3.2.jar:1.3.2]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_211]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_211]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_211]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_211]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	... 62 common frames omitted

Problem analysis:

    Error creating bean with name 'customMetadataSource': Unsatisfied dependency expressed through field 'menuService' prompts you to fail to create customMetadataSource this bean failed because you cannot create internal menuService; Error creating bean with name 'menuService' menuService, because menuMapper; Error creating bean with name 'menuMapper' defined in file prompts the creation of menuMapper this bean fails, and finally it is found that menuMapper fails to create, and then the problem is eliminated.

Screen:
Make sure that menumapper. Java and menumapper. XML are spelled correctly; Make sure that menuService method is added before @service , otherwise it will be prompted that this Service cannot be found; Make sure that MenuService method internal use MenuMapper, use @autowired into the injection; Make sure to add the annotation @mapperscan ("mapper's package name ") before starting the class, which can scan the code>mapper
;
I have checked the above, no mistake! After making this mistake for a long time, I finally found out: In application.properties, configure mybatis config. location=classpath:/mybatis config. XML menumapper. XML
and manumapper. Java are placed under the same package instead of under the resources folder. Therefore, the mybatis config. XML that I configured could not be found. Of course, it was suggested to create MenuMapper; this bean failed, and the problem was finally solved!
If students encounter similar problems, one by one to check, if through the above method or not solved, you can leave a message to exchange, learn from each other!! Together on the way to change the bug more powerful!!

Springboot project startup exception – required a single bean, but 2 were found

springboot project startup exception – required a single bean, but 2 were found

    • description
    • detailed error message
    • error analysis
    • why
    • solution

    problem description

    springboot+mybatis, write interface and implementation classes, and use @autowired injection controller, start exception: required a single bean, but 2 were found

    controller interface:

    @RestController
    @RequestMapping("/api/sys/statistic")
    public class StatisticController {
    
        @Autowired
        private ISysAccessLogService iSysAccessLogService;
        
    }
    

    interface and implementation class

    detail error

    APPLICATION FAILED TO START
    Description:

    Field iSysAccessLogService in com.msb.sys.controller.StatisticController required a single bean, but 2 were found:
    – sysAccessLogServiceImpl: defined in file [/Users/ronghuilin/java/msbjava/target/classes/com/msb/sys/service/impl/SysAccessLogServiceImpl.class]
    – ISysAccessLogService: defined in file [/Users/ronghuilin/java/msbjava/target/classes/com/msb/sys/service/ISysAccessLogService.class]

    Action:

    Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

    Disconnected from the target VM, address: ‘127.0.0.1:61739’, transport: ‘socket’

    error analysis

    if you’re prompted, there’s no way to automatically inject iSysAccessLogService at StatisticController.

    @autowired is injected by type by default, and as prompted, my project has two beans of this type, so it cannot be injected automatically.

    The

    error message also suggests a solution:
    1. Use one of the beans with the @primary annotation as the default,
    2. Add @qualifier to the injected property to specify beanName to specify which bean

    to use

    but I’ve only written one implementation class for the interface, and as expected there’s only one bean, which should be fine.

    Reason

    after a roundabout search, I found that I had annotated springboot’s boot class with @mapperscan (” “com”).

    @mapperscan this is the annotation is the Mapper scan annotation for mybatis, and the scope of the scan I specified is the com package.
    mybatis scans the interface under com, generates the implementation class of the interface, and infuses it into spring.
    then spring scans the interface implementation class I wrote, injects spring, and you have two beans.

    solution

    in the springboot project it is recommended to add @mapper directly to the Mapper interface and not to use @mapperscan.

    if you want to use @mapperscan annotations, be careful to configure the scope of the scan to avoid the above problems caused by repeat scan injection of spring beans.

Solve the problem that the value in the disabled tag cannot be passed to the server

disable tag values do not pass values to the server

<input type="text" name="did" value="${dept.did}" disabled="disabled"/><br/>

solution

  1. replace the field disabled in the form with readonly (if necessary, add a gray background color to the form)

    <input type="text" name="did" value="${dept.did}" readonly/><br/>
    

  2. you can write a hidden attributes, one for the value of a is used to display

    for example: add a hidden TAB and the name and value are set to the same value as the disable tag to successfully pass the value

    <input type="hidden" name="did" value="${dept.did}" >
    <input type="text" value="${dept.did}" disabled="disabled"/><br/>
    

    disabled

    similarity

    • can make text boxes cannot be entered.
    • can be modified by js script.
    • want to cancel, can only delete the corresponding attribute, set flase invalid

    different points

    disabled

    • input cannot receive focus
    • using the TAB key will skip the element
    • disabled will not respond to any event (e.g. the click event is invalid). The value of the disabled element
    • is not committed. The
    • disabled property can be used on all form elements.

    readonly

    • input can receive focus
    • use the TAB key does not skip elements
    • readonly will respond to events.
    • readonly element values are submitted. The
    • readonly property is only valid for type= “text”, textarea, and type= “password”.

    disabled will not be submitted to the server can’t be serialized but can be js can’t be modified on the interface all controls have disabled property

    readonly will be submitted to the server can be serialized can be js value assignment interface can’t modify all controls not necessarily have readonly property such as select drop down box

Springboot integrated with mybatis

springBoot integration mybatis

#springBoot integration with the first mybatis project
1. Create a new normal maven project
2. Use idea’s easycode to automatically generate the controller, entity, service and dao layer code
3. Simple pom configuration, independent of error

  java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class tk.mybatis.spring.annotation.MapperScan.factoryBean()

依赖如下:
   <dependency>
       <groupId>org.mybatis.spring.boot</groupId>
       <artifactId>mybatis-spring-boot-starter</artifactId>  
       <version>2.1.0</version>
   </dependency>
    <dependency>
       <groupId>com.oracle</groupId>
       <artifactId>ojdbc6</artifactId>
       <version>11.2.0.4</version>
   </dependency>

4.  配置简单的yml,不配置会报找不到 

mybatis:
mapper-locations:类路径:mapper/* . xml