ssm 整合异常信息整理

1、mybatis与spring整合报错NoClassDefFoundError: org/springframework/jdbc/datasource/TransactionAwareDataSour。

原因:由于缺少spring-jdbc包,导致项目启动一直报错,一直以为是配置文件哪里写错了,最后发现是缺少依赖

 

2、Caused by: java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling

原因:由于指定的类中包含了含有@EnableWebMvc注解的类,所以出现上述错误。

解决方案:

方法1:@ContextConfiguration不要包含带有@EnableWebMvc注解的类

放法2:在测试类中加入@WebApplicationContext注解来配置Servlet环境。

 

3、he server time zone value '?й???????' is unrecognized or represents more than one time zone.

解决方案:

扫描二维码关注公众号,回复: 8667630 查看本文章

在数据库驱动的url后加上serverTimezone=UTC参数。写代码的时候要注意,如果该参数是‘?’后的第一个,即

 

<property name="url" value="jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC" />

但如果不是第一个,即

<property name="jdbcUrl"> jdbc:mysql://localhost:3306/mybatis?characterEncoding=utf8&serverTimezone=UTC />

这种写法是会报错的,会提示The reference to entity “serverTimezone” must end with the ‘;’ delimiter.

运行后控制台也会出现 对实体 “serverTimezone” 的引用必须以 ‘;’ 分隔符结尾。

修改为

<property name="jdbcUrl"> jdbc:mysql://localhost:3306/mybatis?characterEncoding=utf8&amp;serverTimezone=UTC />

 

4、一直无法读取properties文件中的数据,

原因:没有注册propertySourcesPlaceholderConfigurer,我以为@PropertySource(value={"classpath:base.properties"})有这个就可以。

 

5、maven打包异常,[ERROR] Failed to execute goal

org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project mavensmvcm: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]

mvn install War包没有jsp页面

解决方案:在pom.xml中增加如下配置:

  <build>

    <plugins>

       <plugin>

            <groupId>org.apache.maven.plugins</groupId>

            <artifactId>maven-war-plugin</artifactId>

            <version>2.1.1</version>

            <configuration>

                <failOnMissingWebXml>false</failOnMissingWebXml>

                <!--指定web.xml文件的位置-->

              <webXml>WebRoot\WEB-INF\web.xml</webXml>            

              <!--指定jsp等文件所在位置-->  

              <warSourceDirectory>WebRoot</warSourceDirectory>

            </configuration>

        </plugin>

    </plugins>

  </build>

6、org.apache.ibatis.binding.BindingException: Parameter 'userName' not found. Available parameters are [arg1, arg0, param1, param2]

原因:Dao层的抽象方法中,传递了多于1个参数,User findUserByNamePwd(String userName,String userPass);然后就会异常

解决方案:User findUserByNamePwd(@Param("userName") String userName,@Param("userPass") String userPass);

参考资料:https://blog.csdn.net/ITBigGod/article/details/82970621

7、HTTP Status 406 – Not Acceptable

解决方案:

dispatcher-servlet.xml中加入<mvc:annotation-driven/>
导入指定的json工具包(我的springmvc是4.x):jackson-annotations-2.9.6.jar jackson-core-2.9.6.jar jackson-databind-2.9.6.jar

8、spring mvc 无法启动。异常信息:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultServletHandlerMapping' defined in class org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.web.servlet.HandlerMapping org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.defaultServletHandlerMapping()] threw exception; nested exception is java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling

还未解决,后续更新

发布了39 篇原创文章 · 获赞 12 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/yanweijie0317/article/details/97249952