先看启动web项目时IDEA控制台抛出的异常(红色部分):

D:\tomcat-kafka-\bin\catalina.bat run
[-- ::,] Artifact Gradle : com.xbs:imcc : imcc-1.0-SNAPSHOT.war (exploded): Server is not connected. Deploy is not available.
Using CATALINA_BASE: "C:\Users\SYJ\.IntelliJIdea14\system\tomcat\Unnamed_imcc_4"
Using CATALINA_HOME: "D:\tomcat-kafka-8080"
Using CATALINA_TMPDIR: "D:\tomcat-kafka-8080\temp"
Using JRE_HOME: "D:\java\jdk1.8.0_121"
Using CLASSPATH: "D:\tomcat-kafka-8080\bin\bootstrap.jar;D:\tomcat-kafka-8080\bin\tomcat-juli.jar"
四月 , :: 下午 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\java\jdk1..0_121\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:\java\scala\bin;D:\java\gradle-3.3\bin;D:\java\spark-1.6.-bin-hadoop2.\bin;D:\hadoop-2.6.\bin;D:\apache-maven-3.2.\bin;D:\apache-cxf-3.1.\apache-cxf-3.1.\bin;D:\java\jdk1..0_121\bin;%CATALINA_HOME%\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.\;C:\Program Files\Lenovo\Fingerprint Manager Pro\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;D:\java\mysql5.\bin;D:\java\scala\bin;C:\Program Files\MySQL\MySQL Utilities 1.6\;F:\SVN\VisualSVNServer\bin;D:\java\TortoiseGit\bin;D:\java\TortoiseSVN-1.8.\bin;D:\soft\ssh;.
四月 , :: 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-nio-8080"]
四月 , :: 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
信息: Using a shared selector for servlet write/read
四月 , :: 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["ajp-bio-8009"]
四月 , :: 下午 org.apache.catalina.startup.Catalina load
信息: Initialization processed in ms
四月 , :: 下午 org.apache.catalina.core.StandardService startInternal
信息: Starting service Catalina
四月 , :: 下午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.
四月 , :: 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-nio-8080"]
四月 , :: 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-bio-8009"]
四月 , :: 下午 org.apache.catalina.startup.Catalina start
信息: Server startup in ms
Connected to server
[-- ::,] Artifact Gradle : com.xbs:imcc : imcc-1.0-SNAPSHOT.war (exploded): Artifact is being deployed, please wait...
四月 , :: 下午 org.apache.catalina.loader.WebappClassLoader validateJarFile
信息: validateJarFile(E:\imcc\out\artifacts\imcc\exploded\imcc-1.0-SNAPSHOT.war\WEB-INF\lib\javax.servlet-api-3.0..jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.. Offending class: javax/servlet/Servlet.class
四月 , :: 下午 org.apache.catalina.loader.WebappClassLoader validateJarFile
信息: validateJarFile(E:\imcc\out\artifacts\imcc\exploded\imcc-1.0-SNAPSHOT.war\WEB-INF\lib\servlet-api-2.4.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.. Offending class: javax/servlet/Servlet.class
四月 , :: 下午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/core_rt is already defined
四月 , :: 下午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/core is already defined
四月 , :: 下午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/core is already defined
四月 , :: 下午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/fmt_rt is already defined
四月 , :: 下午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/fmt is already defined
四月 , :: 下午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/fmt is already defined
四月 , :: 下午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/functions is already defined
四月 , :: 下午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/permittedTaglibs is already defined
四月 , :: 下午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/scriptfree is already defined
四月 , :: 下午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/sql_rt is already defined
四月 , :: 下午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/sql is already defined
四月 , :: 下午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/sql is already defined
四月 , :: 下午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/xml_rt is already defined
四月 , :: 下午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined
四月 , :: 下午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/xml is already defined
log4j:WARN No such property [conversionPattern] in net.logstash.log4j.JSONEventLayoutV1.
-- ::, INFO ContextLoader: - Root WebApplicationContext: initialization started
-- ::, INFO XmlWebApplicationContext: - Refreshing Root WebApplicationContext: startup date [Sun Apr :: CST ]; root of context hierarchy
-- ::, INFO XmlBeanDefinitionReader: - Loading XML bean definitions from class path resource [spring/applicationContext.xml]
-- ::, INFO PropertySourcesPlaceholderConfigurer: - Loading properties file from file [E:\imcc\out\artifacts\imcc\exploded\imcc-1.0-SNAPSHOT.war\WEB-INF\classes\resource\db.properties]
-- ::, INFO PropertySourcesPlaceholderConfigurer: - Loading properties file from file [E:\imcc\out\artifacts\imcc\exploded\imcc-1.0-SNAPSHOT.war\WEB-INF\classes\resource\resource.properties]
-- ::, INFO AutowiredAnnotationBeanPostProcessor: - JSR- 'javax.inject.Inject' annotation found and supported for autowiring
-- ::, WARN XmlWebApplicationContext: - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.xbs.service.PersonService com.xbs.api.PersonController.personService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.xbs.dao.PersonDao com.xbs.service.impl.PersonServiceImpl.personDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personDaoImpl' defined in file [E:\imcc\out\artifacts\imcc\exploded\imcc-1.0-SNAPSHOT.war\WEB-INF\classes\com\xbs\dao\impl\PersonDaoImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory$.getObject(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:)
at javax.management.remote.rmi.RMIConnectionImpl.access$(RMIConnectionImpl.java:)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:)
at sun.rmi.transport.Transport$.run(Transport.java:)
at sun.rmi.transport.Transport$.run(Transport.java:)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$(TCPTransport.java:)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:)
at java.lang.Thread.run(Thread.java:)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.xbs.service.PersonService com.xbs.api.PersonController.personService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.xbs.dao.PersonDao com.xbs.service.impl.PersonServiceImpl.personDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personDaoImpl' defined in file [E:\imcc\out\artifacts\imcc\exploded\imcc-1.0-SNAPSHOT.war\WEB-INF\classes\com\xbs\dao\impl\PersonDaoImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:)
... more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.xbs.dao.PersonDao com.xbs.service.impl.PersonServiceImpl.personDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personDaoImpl' defined in file [E:\imcc\out\artifacts\imcc\exploded\imcc-1.0-SNAPSHOT.war\WEB-INF\classes\com\xbs\dao\impl\PersonDaoImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory$.getObject(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:)
... more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.xbs.dao.PersonDao com.xbs.service.impl.PersonServiceImpl.personDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personDaoImpl' defined in file [E:\imcc\out\artifacts\imcc\exploded\imcc-1.0-SNAPSHOT.war\WEB-INF\classes\com\xbs\dao\impl\PersonDaoImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:)
... more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personDaoImpl' defined in file [E:\imcc\out\artifacts\imcc\exploded\imcc-1.0-SNAPSHOT.war\WEB-INF\classes\com\xbs\dao\impl\PersonDaoImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory$.getObject(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:)
... more
Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
at org.springframework.util.Assert.notNull(Assert.java:)
at org.mybatis.spring.support.SqlSessionDaoSupport.checkDaoConfig(SqlSessionDaoSupport.java:)
at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:)
... more
-- ::, ERROR ContextLoader: - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.xbs.service.PersonService com.xbs.api.PersonController.personService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.xbs.dao.PersonDao com.xbs.service.impl.PersonServiceImpl.personDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personDaoImpl' defined in file [E:\imcc\out\artifacts\imcc\exploded\imcc-1.0-SNAPSHOT.war\WEB-INF\classes\com\xbs\dao\impl\PersonDaoImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory$.getObject(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:)
at javax.management.remote.rmi.RMIConnectionImpl.access$(RMIConnectionImpl.java:)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:)
at sun.rmi.transport.Transport$.run(Transport.java:)
at sun.rmi.transport.Transport$.run(Transport.java:)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$(TCPTransport.java:)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:)
at java.lang.Thread.run(Thread.java:)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.xbs.service.PersonService com.xbs.api.PersonController.personService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.xbs.dao.PersonDao com.xbs.service.impl.PersonServiceImpl.personDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personDaoImpl' defined in file [E:\imcc\out\artifacts\imcc\exploded\imcc-1.0-SNAPSHOT.war\WEB-INF\classes\com\xbs\dao\impl\PersonDaoImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:)
... more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.xbs.dao.PersonDao com.xbs.service.impl.PersonServiceImpl.personDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personDaoImpl' defined in file [E:\imcc\out\artifacts\imcc\exploded\imcc-1.0-SNAPSHOT.war\WEB-INF\classes\com\xbs\dao\impl\PersonDaoImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory$.getObject(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:)
... more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.xbs.dao.PersonDao com.xbs.service.impl.PersonServiceImpl.personDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personDaoImpl' defined in file [E:\imcc\out\artifacts\imcc\exploded\imcc-1.0-SNAPSHOT.war\WEB-INF\classes\com\xbs\dao\impl\PersonDaoImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:)
... more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personDaoImpl' defined in file [E:\imcc\out\artifacts\imcc\exploded\imcc-1.0-SNAPSHOT.war\WEB-INF\classes\com\xbs\dao\impl\PersonDaoImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory$.getObject(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:)
... more
Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
at org.springframework.util.Assert.notNull(Assert.java:)
at org.mybatis.spring.support.SqlSessionDaoSupport.checkDaoConfig(SqlSessionDaoSupport.java:)
at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:)
... more
log4j:WARN No such property [conversionPattern] in net.logstash.log4j.JSONEventLayoutV1.
四月 , :: 下午 org.apache.catalina.core.StandardContext startInternal
严重: Error listenerStart
四月 , :: 下午 org.apache.catalina.core.StandardContext startInternal
严重: Context [] startup failed due to previous errors
[-- ::,] Artifact Gradle : com.xbs:imcc : imcc-1.0-SNAPSHOT.war (exploded): Error during artifact deployment. See server log for details.

意思是说没有找到sqlSessionFactory或者sqlSessionTemplate属性。为什么呢?

我的项目使用的mybatis的版本如下(gradle):

compile "org.mybatis:mybatis:3.3.0"
compile "org.mybatis:mybatis-spring:1.2.3"

在项目中的Dao层是这样使用使用SQLSession的:

package com.xbs.dao.impl;

import java.util.List;
import java.util.Map; import com.xbs.dao.PersonDao;
import com.xbs.model.Person;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository; @Repository
public class PersonDaoImpl extends SqlSessionDaoSupport implements PersonDao { String ns = "sql.mapper.PersonMapper.";
@Override
public void save(Person p) {
this.getSqlSession().insert(ns+"insert", p);
} @Override
public Person selectPersonById(Integer personId) {
return (Person) this.getSqlSession().selectOne(ns+"selectPersonByIdWithRM", personId);
} @Override
public void update(Person p) {
this.getSqlSession().update(ns+"dynamicUpdate", p);
} @Override
public void delete(Integer personId) {
this.getSqlSession().delete(ns+"delete", personId);
} @Override
public List<Person> selectPersonByCondition(Map<String, Object> map) {
return this.getSqlSession().selectList(ns+"selectPersonByCondition", map);
} }

Dao层继承了SqlSessionDaoSupport,该类会自动注入SQLSessionFectory,我们只要使用this.getSqlSession()就可以拿到SqlSession。

但是如果使用的是"mybatis-spring-1.0.0-RC3.jar"这个版本是没有问题的。但是高版本就会有问题,原因是Mybatis3依赖的jar包"mybatis-spring-1.2.0.jar"这个版本以及以上的版本中,对SqlSessionDaoSupport类中的'sqlSessionFactory'或'sqlSessionTemplate'注入方式进行了调整。

可能是为了解决多数据源的问题吧,取消了自动注入。

解决办法:创建一个Dao的基类CommonDao,让这个基类继承SqlSessionDaoSupport,并通过set方法注入SqlSessionFactory属性即可:

/**
* Created by SYJ on 2017/4/16.
*/
public class CommonDao extends SqlSessionDaoSupport {
@Resource
public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory){
super.setSqlSessionFactory(sqlSessionFactory);
}
}

然后让Dao实现类再继承这个CommonDao基类即可:

@Repository
public class PersonDaoImpl extends CommonDao implements PersonDao {
//此处省略...
}

重新启动web项目,问题解决。

如果觉得本文对您有帮助,不妨扫描下方微信二维码打赏点,您的鼓励是我前进最大的动力:

Spring和Mybatis整合过程中遇到的一个找不到sqlSessionFactory或sqlSessionTemplate的异常-LMLPHP

05-08 15:48