天天看點

SSM架構整合遇到的問題彙總(Spring+SpringMVC+Mybatis+PostgreSQL+Tomcat7+Maven)v.18一二三:四五:六七八九十十一十二十三十四十五十六十七十八

    • 問題一:mybatis生成的映射檔案1 (mapper.xml)找不到:
      • 解決辦法:
    • 問題二:mappingJacksonHttpMessageConverter類找不到
      • 解決辦法:
  • 三:
    • 問題三:jackson.core找不到
      • 解決辦法:
    • 問題四:web容器找不到資料庫驅動org.postgresql.Driver
      • 解決辦法:-将驅動jar包 手動放入web容器lib目錄下
  • 五:
    • 問題五:JDBC連接配接中DB使用者名role “prostgres” 不存在
      • 解決辦法:
    • 問題六:postgresql字段id等找不到
      • 解決辦法:
    • 問題七:js、css等檔案找不到
      • 解決辦法:
        • 辦法一:
        • 辦法二
    • 問題八parameter is not present
      • 思路:
      • 解決辦法:
    • 問題九Parameter ‘xx’ not found
      • 解決辦法:
    • 問題十 Can’t find bundle for base name javax.servlet.LocalStrings, locale zh_CN
      • 原因:
      • 解決辦法:
  • 十一
    • 問題十一 SerializationFailedException: Failed to serialize object using DefaultSerializer
      • 原因:
      • 解決辦法:
  • 十二
    • 問題十二 The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path
      • 原因: javax.api jar包未引入。
      • 解決辦法:引入jar包。
  • 十三
    • 問題十三 cannot change version of project facet Dynamic Web Module to 3.0
      • 原因:
      • 解決辦法:
  • 十四
    • 問題十四 Result Maps collection already contains value for *.ThesisMapper.BaseResultMap
  • 十五
    • 問題十五 column “xxx” does not exist
  • 十六
    • 問題十六 javax.naming.NameNotFoundException:
      • 原因:
      • 解決辦法:
  • 十七
    • 問題十七 SpringMVC response傳回前台的漢字亂碼’?’:
  • 十八
    • 問題十八 批量插入時JDBC參數超出數量限制:
  • 在學習整合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  :: CST ]; 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-/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-/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  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-/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-/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  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-/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-/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:)

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  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:)

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'site.gaoyisheng.dao.UserMapper' available: expected at least  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:)
    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
Related cause:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userMapper' defined in file [/home/gaoyisheng/devel/tomcat/Tomcat-/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:)

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:)

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:)

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:)

Related cause:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userMapper' defined in file [/home/gaoyisheng/devel/tomcat/Tomcat-/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:)

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:)

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:)

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:)
           

原因:沒有将檔案添加到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  :: CST ]; 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  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  :: CST ]; 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:)

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:)

九月 ,  :: 下午 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:)


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:)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:)
    ...  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-/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-/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
  位置:
### 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
  位置:
; bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: ERROR: column "id" does not exist
  位置:
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:)



root cause


org.springframework.jdbc.BadSqlGrammarException: 
### Error querying database.  Cause: org.postgresql.util.PSQLException: ERROR: column "id" 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-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
  位置:
; bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: ERROR: column "id" does not exist
  位置:
    org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:)
    org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:)
    org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:)

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


           

解決辦法:

修改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

或者 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 [org.springframework.test.context.web.ServletTestExecutionListener@7dc7cbad] to prepare test instance [[email protected]]
  [org.springframework.test.context.TestContextManager] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@7dc7cbad] to prepare test instance [me.tes[email protected]]
  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 = -L;
    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".
  位置:
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".
  位置:
; bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: ERROR: column "未認領" does not exist
  建議:Perhaps you meant to reference the column "e.id".
  位置:

Caused by: org.postgresql.util.PSQLException: ERROR: column "未認領" does not exist
  建議:Perhaps you meant to reference the column "e.id".
  位置:
           

原因:

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>
           

參考資料:

https://stackoverflow.com/questions/23750619/spring-jndi-namingexception-name-spring-livebeansview-mbeandomain-is-not-boun

https://oschina.net/question/238156_135712

十七

問題十七 SpringMVC response傳回前台的漢字亂碼’?’:

解決辦法:

1.

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>.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 ↩

繼續閱讀