Eclipse搭建SpringMVC遇到的问题过程

来源:互联网 发布:vs2013字体推荐知乎 编辑:程序博客网 时间:2024/05/16 16:01

问题一、设置tomcat

     

双击

设置图中选项(这样就能在Eclipse启动tomcat了):



问题二、tomcat启动时出现:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError

导入图片中这4个包就可以了


问题三、mysql数据库乱码,导致插入出现如下问题:

MysqlDataTruncation: Data truncation: Data too long for column 'username' at  at row 1”。

    解决:设置三个点

               1。创建数据库的时候:CREATE   DATABASE   `database` 
                                                CHARACTER   SET   'utf8 ' 
                                                  COLLATE   'utf8_general_ci '; 
              2.建表的时候                CREATE   TABLE   `database_user`   ( 
                                                `ID`   varchar(40)   NOT   NULL   default   ' ', 
                                                `UserID`   varchar(40)   NOT   NULL   default   ' ', 
                                            )   ENGINE=InnoDB   DEFAULT   CHARSET=utf8; 

           3.设置URL的时候               jdbc:mysql://localhost:3306/database?seUnicode=true&characterEncoding=UTF-8 

           其中,dataSource的属性url链接数据库时,若在xml设置的,需要转码:如

          

正确的写法:

<property name="url" value="jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=utf-8" />

在xml文件中有以下几类字符要进行转义替换:

&lt;

<

小于号

&gt;

>

大于号

&amp;

&

&apos;

'

单引号

&quot;

"

双引号


问题四、注意事项

          在Service或Dao里,需要加入事务注解@Transactional,不然会报错:

  org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one       here] with root cause



问题五、使用HttpServletRequest request报错 

The type javax.servlet.http.HttpServlet cannot be resolved. It is indirect

javax.servlet.http.HttpServletRequest 类报错

在lib文件下,导入这个包,该包在Tomcat的安装目录的lib文件夹下。

以下是简单的SpringMVC整合包:

http://download.csdn.net/detail/klx502/8550895 

0 0
原创粉丝点击