欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SSM框架整合遇到的问题汇总(Spring+SpringMVC+Mybatis+PostgreSQL+Tomcat7+Maven)v.18

程序员文章站 2024-03-21 23:57:46
...

  • 在学习整合spring+springMVC+Mybatis过程中遇到的问题全部整理罗列如此。供自己以后翻阅使用。也方便大家学习和交流。

  • 欢迎翻阅GitHub查找全部代码



问题一:mybatis生成的映射文件1 (mapper.xml)找不到:

信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
[org.springframework.web.context.ContextLoader] - Root WebApplicationContext: initialization started
  [org.springframework.web.context.support.XmlWebApplicationContext] - Refreshing Root WebApplicationContext: startup date [Mon Sep 18 21:59:28 CST 2017]; root of context hierarchy
  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from class path resource [spring-mybatis.xml]
  [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer] - Loading properties file from class path resource [jdbc.properties]
  [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Bean creation exception on non-lazy FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userMapper' defined in file [/home/gaoyisheng/devel/tomcat/Tomcat-7.0.81/webapps/${fileName}/WEB-INF/classes/site/gaoyisheng/dao/UserMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Initialization of bean failed; nested exception is 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:site/gaoyisheng/mapping/*.xml]: class path resource [site/gaoyisheng/mapping/] cannot be resolved to URL because it does not exist
  [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Bean creation exception on non-lazy FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userMapper' defined in file [/home/gaoyisheng/devel/tomcat/Tomcat-7.0.81/webapps/${fileName}/WEB-INF/classes/site/gaoyisheng/dao/UserMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Initialization of bean failed; nested exception is 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:site/gaoyisheng/mapping/*.xml]: class path resource [site/gaoyisheng/mapping/] cannot be resolved to URL because it does not exist
  [org.springframework.web.context.support.XmlWebApplicationContext] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userService': Unsatisfied dependency expressed through field 'userDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'site.gaoyisheng.dao.UserMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userMapper' defined in file [/home/gaoyisheng/devel/tomcat/Tomcat-7.0.81/webapps/${fileName}/WEB-INF/classes/site/gaoyisheng/dao/UserMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Initialization of bean failed; nested exception is 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:site/gaoyisheng/mapping/*.xml]: class path resource [site/gaoyisheng/mapping/] cannot be resolved to URL because it does not exist
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userMapper' defined in file [/home/gaoyisheng/devel/tomcat/Tomcat-7.0.81/webapps/${fileName}/WEB-INF/classes/site/gaoyisheng/dao/UserMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Initialization of bean failed; nested exception is 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:site/gaoyisheng/mapping/*.xml]: class path resource [site/gaoyisheng/mapping/] cannot be resolved to URL because it does not exist
  [org.springframework.web.context.ContextLoader] - Context initialization failed
  org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userService': Unsatisfied dependency expressed through field 'userDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'site.gaoyisheng.dao.UserMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userMapper' defined in file [/home/gaoyisheng/devel/tomcat/Tomcat-7.0.81/webapps/${fileName}/WEB-INF/classes/site/gaoyisheng/dao/UserMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Initialization of bean failed; nested exception is 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:site/gaoyisheng/mapping/*.xml]: class path resource [site/gaoyisheng/mapping/] cannot be resolved to URL because it does not exist
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userMapper' defined in file [/home/gaoyisheng/devel/tomcat/Tomcat-7.0.81/webapps/${fileName}/WEB-INF/classes/site/gaoyisheng/dao/UserMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Initialization of bean failed; nested exception is 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:site/gaoyisheng/mapping/*.xml]: class path resource [site/gaoyisheng/mapping/] cannot be resolved to URL because it does not exist
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userService': Unsatisfied dependency expressed through field 'userDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'site.gaoyisheng.dao.UserMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'site.gaoyisheng.dao.UserMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1486)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
    ... 72 more
Related cause:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userMapper' defined in file [/home/gaoyisheng/devel/tomcat/Tomcat-7.0.81/webapps/${fileName}/WEB-INF/classes/site/gaoyisheng/dao/UserMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Initialization of bean failed; nested exception is 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:site/gaoyisheng/mapping/*.xml]: class path resource [site/gaoyisheng/mapping/] cannot be resolved to URL because it does not exist
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Initialization of bean failed; nested exception is 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:site/gaoyisheng/mapping/*.xml]: class path resource [site/gaoyisheng/mapping/] cannot be resolved to URL because it does not exist
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564)

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:site/gaoyisheng/mapping/*.xml]: class path resource [site/gaoyisheng/mapping/] cannot be resolved to URL because it does not exist
    at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:610)

Caused by: java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:site/gaoyisheng/mapping/*.xml]: class path resource [site/gaoyisheng/mapping/] cannot be resolved to URL because it does not exist
    at org.springframework.core.io.support.ResourceArrayPropertyEditor.setAsText(ResourceArrayPropertyEditor.java:116)

Related cause:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userMapper' defined in file [/home/gaoyisheng/devel/tomcat/Tomcat-7.0.81/webapps/${fileName}/WEB-INF/classes/site/gaoyisheng/dao/UserMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Initialization of bean failed; nested exception is 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:site/gaoyisheng/mapping/*.xml]: class path resource [site/gaoyisheng/mapping/] cannot be resolved to URL because it does not exist
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Initialization of bean failed; nested exception is 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:site/gaoyisheng/mapping/*.xml]: class path resource [site/gaoyisheng/mapping/] cannot be resolved to URL because it does not exist
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564)

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:site/gaoyisheng/mapping/*.xml]: class path resource [site/gaoyisheng/mapping/] cannot be resolved to URL because it does not exist
    at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:610)

Caused by: java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:site/gaoyisheng/mapping/*.xml]: class path resource [site/gaoyisheng/mapping/] cannot be resolved to URL because it does not exist
    at org.springframework.core.io.support.ResourceArrayPropertyEditor.setAsText(ResourceArrayPropertyEditor.java:116)

原因:没有将文件添加到resources

解决办法:

pom.xml文件中引入包含依赖:

solutions:
pom.xml appends follows:

<resources>
      <resource>
        <directory>src/main/resources</directory>
        <includes>
          <include>**/*.properties</include>
          <include>**/*.xml</include>
          <include>**/*.tld</include>
        </includes>
        <filtering>false</filtering>
      </resource>
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.properties</include>
          <include>**/*.xml</include>
          <include>**/*.tld</include>
        </includes>
        <filtering>false</filtering>
      </resource>
</resources>


问题二:mappingJacksonHttpMessageConverter类找不到

question2

信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
[org.springframework.web.context.ContextLoader] - Root WebApplicationContext: initialization started
  [org.springframework.web.context.support.XmlWebApplicationContext] - Refreshing Root WebApplicationContext: startup date [Mon Sep 18 22:46:57 CST 2017]; root of context hierarchy
  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from class path resource [spring-mybatis.xml]
  [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer] - Loading properties file from class path resource [jdbc.properties]
  [org.springframework.web.context.ContextLoader] - Root WebApplicationContext: initialization completed in 609 ms
  [org.springframework.web.servlet.DispatcherServlet] - FrameworkServlet 'SpringMVC': initialization started
  [org.springframework.web.context.support.XmlWebApplicationContext] - Refreshing WebApplicationContext for namespace 'SpringMVC-servlet': startup date [Mon Sep 18 22:46:58 CST 2017]; parent: Root WebApplicationContext
  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from class path resource [spring-mvc.xml]
  [org.springframework.web.context.support.XmlWebApplicationContext] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter] for bean with name 'mappingJacksonHttpMessageConverter' defined in class path resource [spring-mvc.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
  [org.springframework.web.servlet.DispatcherServlet] - Context initialization failed
  org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter] for bean with name 'mappingJacksonHttpMessageConverter' defined in class path resource [spring-mvc.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)

Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter] for bean with name 'mappingJacksonHttpMessageConverter' defined in class path resource [spring-mvc.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1385)

九月 18, 2017 10:46:58 下午 org.apache.catalina.startup.HostConfig deployWAR

jackson版本有问题
spring4.x依赖org.springframework.http.converter.json.MappingJackson2HttpMessageConverter

解决办法:

修改spring-mvc.xml如下:
so :change spring-mvc.xml like this:

    <!--避免IE执行AJAX时,返回JSON出现下载文件 spring 4.x supported -->
    <bean id="mappingJacksonHttpMessageConverter"
        class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>text/html;charset=UTF-8</value>
            </list>
        </property>
    </bean>
    <!-- 启动SpringMVC的注解功能, -->
    <mvc:annotation-driven>
        <mvc:message-converters register-defaults="true">
            <bean
                class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"
                p:supportedMediaTypes="*/*" />
        </mvc:message-converters>
    </mvc:annotation-driven>

from:http://blog.csdn.net/vili_sky/article/details/73105550
thanks!



三:

问题三:jackson.core找不到

question:

  [org.springframework.web.context.support.XmlWebApplicationContext] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappingJacksonHttpMessageConverter': Failed to introspect bean class [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingException
  [org.springframework.web.servlet.DispatcherServlet] - Context initialization failed
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappingJacksonHttpMessageConverter': Failed to introspect bean class [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingException
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:269)


Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingException
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.getDeclaredMethods(Class.java:1975)
    at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:613)
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:524)
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:510)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:247)
    ... 65 more
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.JsonProcessingException
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1892)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1735)
    ... 72 more

解决办法:

solution:
添加maven依赖:
adding following dependencies in pom.xml


    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.6.3</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.6.3</version>
    </dependency>


问题四:web容器找不到数据库驱动org.postgresql.Driver

question3


严重: Servlet.service() for servlet [SpringMVC] in context with path [/ejos] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'org.postgresql.Driver  '
### The error may exist in file [/home/gaoyisheng/devel/tomcat/Tomcat-7.0.81/webapps/ejos/WEB-INF/classes/site/gaoyisheng/dao/mapping/UserMapper.xml]
### The error may involve site.gaoyisheng.dao.UserMapper.selectByPrimaryKey
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'org.postgresql.Driver  '] with root cause
java.lang.ClassNotFoundException: org.postgresql.Driver  

原因:tomcat找不到驱动class
reason:tomcat cannot find Driver class

解决办法:-将驱动jar包 手动放入web容器lib目录下

web app curtains need jar.

solution:
copy ~driver.jar to ${tomcat_home}/lib/



五:

问题五:JDBC连接中DB用户名role “prostgres” 不存在

question

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (FATAL: role "prostgres" does not exist)
### The error may exist in file [/home/gaoyisheng/devel/tomcat/Tomcat-7.0.81/webapps/ejos/WEB-INF/classes/site/gaoyisheng/dao/mapping/UserMapper.xml]
### The error may involve site.gaoyisheng.dao.UserMapper.selectByPrimaryKey
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (FATAL: role "prostgres" does not exist)

解决办法:

solution
check the username in jdbc.properties



问题六:postgresql字段id等找不到

exception: mybatis + postgresql

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: 
### Error querying database.  Cause: org.postgresql.util.PSQLException: ERROR: column "id" does not exist
  位置:19
### The error may exist in file [/home/gaoyisheng/devel/tomcat/Tomcat-7.0.81/webapps/ejos/WEB-INF/classes/site/gaoyisheng/dao/mapping/UserMapper.xml]
### The error may involve site.gaoyisheng.dao.UserMapper.selectByPrimaryKey-Inline
### The error occurred while setting parameters
### SQL: select            id, username, password, age         from user     where id = ?
### Cause: org.postgresql.util.PSQLException: ERROR: column "id" does not exist
  位置:19
; bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: ERROR: column "id" does not exist
  位置:19
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)



root cause


org.springframework.jdbc.BadSqlGrammarException: 
### Error querying database.  Cause: org.postgresql.util.PSQLException: ERROR: column "id" does not exist
  位置:19
### The error may exist in file [/home/gaoyisheng/devel/tomcat/Tomcat-7.0.81/webapps/ejos/WEB-INF/classes/site/gaoyisheng/dao/mapping/UserMapper.xml]
### The error may involve site.gaoyisheng.dao.UserMapper.selectByPrimaryKey-Inline
### The error occurred while setting parameters
### SQL: select            id, username, password, age         from user     where id = ?
### Cause: org.postgresql.util.PSQLException: ERROR: column "id" does not exist
  位置:19
; bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: ERROR: column "id" does not exist
  位置:19
    org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:99)
    org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
    org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)

    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

解决办法:

修改SQL(mapper.xml)中表名,
solution:
in mapper.xml

  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">

    select 
    <include refid="Base_Column_List" />
    from user
    where id = #{id,jdbcType=INTEGER}
  </select>

to

from public."user"

或者 public.user



问题七:js、css等文件找不到

SSM框架整合遇到的问题汇总(Spring+SpringMVC+Mybatis+PostgreSQL+Tomcat7+Maven)v.18

<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

HTTP/1.1 404 not fond

原因:文件路径解析时被springmvc过滤了,影响资源文件的获取.

解决办法:

办法一:

更改过滤规则

<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<!-- ... -->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>

办法二

直接配置资源,web容器启动时便载入

<mvc:resources mapping="/javascript/**"
               location="/static_resources/javascript/"/>
<mvc:resources mapping="/styles/**"
               location="/static_resources/css/"/>
<mvc:resources mapping="/images/**"
               location="/static_resources/images/"/>
<mvc:default-servlet-handler /> 

参考资料:感谢!
http://blog.csdn.net/huangjie515/article/details/53509050



问题八parameter is not present

使用SpringMVC注解@RequestParam的”Required String parameter is not present”

SSM框架整合遇到的问题汇总(Spring+SpringMVC+Mybatis+PostgreSQL+Tomcat7+Maven)v.18

controller:

@Controller
@RequestMapping("/user")
public class LoginController {

    @Autowired
    private LoginService loginService;

    @RequestMapping("/login")
    @ResponseBody
    public String login(HttpServletRequest request, Model model, @RequestParam("number") String number,
            @RequestParam("password") String password) {
    //logical code...

.jsp

    <input id="number" name="number" type="text" placeholder="登录账号"
        onkeypress="check_values();" /> 
    <input id="password" name="password" type="password" placeholder="输入密码"  
            onkeypress="check_values();" />

error:
message : Required String parameter ‘number’ is not present
description : The request sent by the client was syntactically incorrect.

参数在语法上匹配不上…

{还有偶遇其他问题:
cannot be translated into a null value
Consider declaring it as object wrapper for the corresponding primitive type

思路:

  1. 检查 @RequestParam (value = “action” 的值
  2. 检查 @ResponseBody 的错用 (参考)
  3. 检查

解决办法:

参考:
http://blog.csdn.net/qq_26761587/article/details/73691189

http://blog.csdn.net/hellostory/article/details/7519358

问题九Parameter ‘xx’ not found

Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘number’ not found. Available parameters are [arg1, arg0, param1, param2]

    <select id="selectByNumberAndPassword" resultType="site.gaoyisheng.pojo.User">
        <!-- by GaoYisheng | for login -->
        select
        u
        from public."user" u
        where u.number = #{number,jdbcType=CHAR}
        And u.password = #{password,jdbcType=CHAR}
    </select>

原因:
mybatis不识别parameter ‘xx’

解决办法:

一:将命名传参改为序号传参

二:

参考资料:
http://www.cnblogs.com/yangchas/p/7383841.html

问题十 Can’t find bundle for base name javax.servlet.LocalStrings, locale zh_CN

SSM框架整合遇到的问题汇总(Spring+SpringMVC+Mybatis+PostgreSQL+Tomcat7+Maven)v.18

  [ERROR] [2017-10-07 14:40:03][org.springframework.test.context.TestContextManager]Caught exception while allowing TestExecutionListener [oraaa@qq.com7dc7cbad] to prepare test instance [aaa@qq.com]
  [org.springframework.test.context.TestContextManager] - Caught exception while allowing TestExecutionListener [oraaa@qq.com7dc7cbad] to prepare test instance [aaa@qq.com]
  java.lang.ExceptionInInitializerError
    at org.springframework.mock.web.MockHttpServletResponse.<init>(MockHttpServletResponse.java:86)
    at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:209)

Caused by: java.util.MissingResourceException: Can't find bundle for base name javax.servlet.LocalStrings, locale zh_CN
    at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1564)

    ... 25 more

原因:

缺少WEB服务运行环境的相关依赖包。

解决办法:

通过build path 添加依赖包
1.项目右键,build path ->

  • SSM框架整合遇到的问题汇总(Spring+SpringMVC+Mybatis+PostgreSQL+Tomcat7+Maven)v.18

2.添加依赖:

  • SSM框架整合遇到的问题汇总(Spring+SpringMVC+Mybatis+PostgreSQL+Tomcat7+Maven)v.18

3.添加倚赖:运行时

  • SSM框架整合遇到的问题汇总(Spring+SpringMVC+Mybatis+PostgreSQL+Tomcat7+Maven)v.18

4.选择容器:

  • SSM框架整合遇到的问题汇总(Spring+SpringMVC+Mybatis+PostgreSQL+Tomcat7+Maven)v.18

5.添加完成如下:

  • SSM框架整合遇到的问题汇总(Spring+SpringMVC+Mybatis+PostgreSQL+Tomcat7+Maven)v.18

6.问题迎刃而解:

  • SSM框架整合遇到的问题汇总(Spring+SpringMVC+Mybatis+PostgreSQL+Tomcat7+Maven)v.18

参考资料:
http://www.cnblogs.com/xdp-blog/p/6168889.html

十一

问题十一 SerializationFailedException: Failed to serialize object using DefaultSerializer

cacheable注解方法缓存实体类List时报错:

Request processing failed; nested exception is org.springframework.data.redis.serializer.SerializationException: Cannot serialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultSerializer; nested exception is java.io.NotSerializableException: site.gaoyisheng.pojo.User

User类如下:

package site.gaoyisheng.pojo;

public class User {
    private Integer id;
    private String number;

    /* setter and getter */
}

原因:

实体类没有实现序列化接口。

解决办法:

实现 Serializable 接口

package site.gaoyisheng.pojo;

import java.io.Serializable;

public class User implements Serializable{
    private static final long serialVersionUID = -48880431122099985L;
    private Integer id;
    private String number;

    /* setter and getter */
}

十二

问题十二 The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path

新maven项目jsp页面报错如下:

The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path

原因: javax.api jar包未引入。

解决办法:引入jar包。

在pom.xml文件中加入:(或者自行将jar包加入依赖)

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
        </dependency>

十三

问题十三 cannot change version of project facet Dynamic Web Module to 3.0

maven webapp + eclipse 创建项目的时候 Dynamic Web Module 的版本切换不了。他要求说 JAVA版本要大于等于1.6。明明JDK也换了,就是不行。
SSM框架整合遇到的问题汇总(Spring+SpringMVC+Mybatis+PostgreSQL+Tomcat7+Maven)v.18

原因:

这应该是Eclipse的一个BUG,就算你后来修改JDK Setting为1.6以上,但是配置文件中的配置不会被修改。需要去手动修改。

解决办法:

手动修改 [ 项目目录下的 ] [.setting] 目录下的
org.eclipse.wst.common.project.facet.core.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <runtime name="Apache Tomcat v7.0"/>
  <fixed facet="wst.jsdt.web"/>
  <installed facet="jst.web" version="3.0"/>
  <installed facet="wst.jsdt.web" version="1.0"/>
  <installed facet="java" version="1.8"/>
</faceted-project>

你的 “jst.web” 和 “java” 的版本值( version= )可能会有问题。修改为你想要的即可。

SSM框架整合遇到的问题汇总(Spring+SpringMVC+Mybatis+PostgreSQL+Tomcat7+Maven)v.18

SSM框架整合遇到的问题汇总(Spring+SpringMVC+Mybatis+PostgreSQL+Tomcat7+Maven)v.18

十四

问题十四 Result Maps collection already contains value for *.ThesisMapper.BaseResultMap

问题描述:
generater自动映射完 ,报错:


java.lang.IllegalStateException: Failed to load ApplicationContext


Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [/home/gaoyisheng/git/trans/target/classes/site/gaoyisheng/dao/mapping/ThesisMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for site.gaoyisheng.dao.ThesisMapper.TheBaseResultMap

Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for site.gaoyisheng.dao.ThesisMapper.TheBaseResultMap


Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for site.gaoyisheng.dao.ThesisMapper.TheBaseResultMap

原因:mapper.xml中 \< BaseResultMap> 生成了两次。

解决办法:
检查logger中指出的mapper.xml文件,删除重复部分即可。

参考资料:
http://wlb.wlb.blog.163.com/blog/static/46741320154145185741/


十五

问题十五 column “xxx” does not exist

握此处的字段为 : 未认领
column “未认领” does not exist
源码

<select id="selectByStatus" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from en_periodical_thesis e
        where e.claim_status = "未认领"
</select>
<select id="selectByStatus" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from en_periodical_thesis e
        where e.claim_status = ${status}
</select>

报错:


**org.springframework.jdbc.BadSqlGrammarException:** 
Error querying database.  Cause: org.postgresql.util.PSQLException: ERROR: column "未认领" does not exist
  建议:Perhaps you meant to reference the column "e.id".
  位置:554
The error may exist in file [/home/gaoyisheng/git/trans/target/classes/site/gaoyisheng/mapping/EnPeriodicalThesisMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select   claim_status      from en_periodical_thesis e   where e.claim_status = 未认领
### Cause: org.postgresql.util.PSQLException: ERROR: column "未认领" does not exist
  建议:Perhaps you meant to reference the column "e.id".
  位置:554
; bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: ERROR: column "未认领" does not exist
  建议:Perhaps you meant to reference the column "e.id".
  位置:554

Caused by: org.postgresql.util.PSQLException: ERROR: column "未认领" does not exist
  建议:Perhaps you meant to reference the column "e.id".
  位置:554

原因:
1. #区别于$,此处应用#
2. 或者 “” 改为 ’ ‘


十六

问题十六 javax.naming.NameNotFoundException:

Converted JNDI name [java:comp/env/spring.liveBeansView.mbeanDomain] not found - trying original name [spring.liveBeansView.mbeanDomain]. javax.naming.NameNotFoundException: Name [spring.liveBeansView.mbeanDomain] is not bound in this Context. Unable to find [spring.liveBeansView.mbeanDomain].

原因:

不明

解决办法:

web.xml 添加:

<context-param>
        <param-name>spring.profiles.active</param-name>  
        <param-value>dev</param-value>  
</context-param>  
<context-param>  
        <param-name>spring.profiles.default</param-name>  
        <param-value>dev</param-value>  
</context-param>
<context-param>  
        <param-name>spring.liveBeansView.mbeanDomain</param-name>  
        <param-value>dev</param-value>  
</context-param>
Found key 'spring.liveBeansView.mbeanDomain' in [servletContextInitParams] with type [String]

参考资料:
https://*.com/questions/23750619/spring-jndi-namingexception-name-spring-livebeansview-mbeandomain-is-not-boun
https://oschina.net/question/238156_135712

十七

问题十七 SpringMVC response返回前台的汉字乱码’?’:

解决办法:

1.

response.setContentType("application/json;charset=UTF-8");//防止数据传递乱码

2.
我使用的Springmvc,在controller层传输一个json到前台,后台显示没问题,中文正常显示而到了前台

中文就变成了问号。

后来发现,因为在controller中返回json用了@ResponseBody,而spring源码中@ResponseBody 的实现类发现其默认的编码是 iso-8859-1,而项目用的编码为utf-8,所以传中文会出现乱码。

这里我使用了注解来解决:

@RequestMapping(value="/echarts.do", produces = "application/json; charset=utf-8")   

这种方法比较适用于新版本的spring,本项目的版本:

<spring.version>4.1.4.RELEASE</spring.version>  

参考:

http://blog.csdn.net/kalision/article/details/46441081
http://blog.csdn.net/qq_32715873/article/details/54581133

十八

问题十八 批量插入时JDBC参数超出数量限制:

java.io.IOException: Tried to send an out-of-range integer as a 2-byte value: 40000

解决办法:
将数据进行分割,分别插入。


  1. mapper.xml