2019.10.10第一次手动编写基于ssm框架的项目"黑马旅游网"注册部分


       这是我第一次自主使用ssm框架编写项目代码,做的项目是网上常见的"黑马旅游网",刚开始我很急躁,以为自己可以随便写写就把注册页面后台代码实现,于是采用了不规范的开发方式(直接编写所有的代码并整合框架,没有分模块进行单元测试),成功的碰见了几个知识盲区,后来因此而老老实实的重新拆开框架进行单元测试排查问题,在此我记录了几个开发过程中碰到的几个坑来警示自己,同时也希望能给刚好也出现这些问题的朋友一个前车之鉴。

Error1.HTTP Status 500 - Servlet.init() for servlet springmvc threw exception

Error creating bean with name ‘userDao’: Unsatisfied dependency expre---------中间部分找不到了---------No qualifying bean of type ‘cn.itcast.travel.dao.IUserDao’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

       以上是我拆完框架之后出现的问题,具体错误字段太长我只找回了当时搜索的这一部分,这是整合前端页面和web层的时候报的错误,我看了一下错误的原因好像是因为创建不了Dao和Service的实现类对象导致了Web层及Service层的注入都失败,由此顺藤摸瓜的想到在我测试完service层和dao层整合成功之后,仅剩的可能性是我写的一个配置文件可能产生在扫描包的时候的故障问题,但由于我的Service层测试成功得出配置文件没有问题,剩下最大的可能就在配置文件的读取上了,打开我的web.xml文件,发现果然因为我的Listener标签在拆分框架时被我注解了忘记打开,打开之后这个问题解决,出现下一个问题。

Error2.HTTP Status 404

       上一个问题在最后一步调整完测试结果出现这个问题,这个我真的一点头绪也没有,我复盘了一下我的代码,觉得没什么语法和拼写上的错误,唯一不确定的是写的springmvc.xml中的视图解析器的配置,因为之前写的都是jsp页面,这次是都html页面,我就照葫芦画瓢的直接把视图解析器的.jsp改成了.html,我猜想可能是由于我的编写不规范导致找不到资源文件,就百度了一下跳转html页面的操作,发现了这篇帖子写的方法:https://blog.csdn.net/just_give_up/article/details/98775300,发现我写的和他写的对比之下唯一的区别是配置静态资源的那一句
<mvc:default-servlet-handler/>,加上之后果然问题解决,页面可以成功访问。

ps: 此项目的前台代码由网课附带,可直接导入IDEA,常见问题还有用Tomcat加载的页面css和js失效,将pom.xml中的servlet-api的2.*版本改为javax-servlet-api的3.*版本即可

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>cn.itcast.parent</groupId> <artifactId>itcast-parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <groupId>cn.itcast</groupId> <artifactId>travel</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>war</packaging> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </dependency> <!-- 连接池 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> </dependency> <!-- Jackson Json处理工具包 --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.9.0</version> </dependency> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4.7</version> </dependency> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> </dependency> </dependencies> <build> <plugins> <!-- 配置Tomcat插件 --> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <configuration> <port>8080</port> <path>/</path> </configuration> </plugin> </plugins> </build> </project>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值