Tomcat8.5.22搭建maven+ssm框架遇到的各种问题

最近学了Java的spring,springmvc,mybatis,以及maven,打算写一个个人网站来锻炼一下整合框架的能力。首先就是搭建ssm框架

写各种配置文件,请参考https://blog.csdn.net/s740556472/article/details/71247285https://blog.csdn.net/qq598535550/article/details/51703190

很快一顿复制粘贴就搭建了一个基本的框架。一切都没有什么不同。但是!!!当你想写代码的时候,你就会遇到各种坑

首先就是运行ssm项目报404的问题,在WEB-INF文件夹下的资源在浏览器端是无法访问的,但是我把它放在根目录下怎么也不能访问???而且更难以理解的是,在这个项目可以访问根目录下的首页,另一个项目就报404,这个坑折磨了我好久,最后安装了Tomcat8.5.22就没出现这个问题(以前的是7.0)

然后能访问首页,打算写个登录界面的时候,复制别人框架配置文件的坑又来了。一开始还是一如既往的404,写好各个层的类和接口,然后登陆界面表单对应的action访问不到,在controller层的对应方法中加上输出语句,发现根本就进不去controller.好吧,打开控制台查看错误信息。复制别人配置文件,比较容易出错的地方有<url-pattern>/</url-pattern>,<url-pattern>/*</url-pattern>可能会报404,还有就是静态资源的访问,比如图片之类的,一般有三种方法

<!-- 对静态资源文件的访问 -->

<mvc:default-servlet-handler/>和
    <mvc:resources location="/resources/img/" mapping="/img/**"/>
    <mvc:resources location="/resources/js/" mapping="/js/**"/>    
    <mvc:resources location="/resources/css/" mapping="/css/**"/>
    <mvc:resources location="/resources/fonts/" mapping="/fonts/**"/>我只试了这两种,

还有就是<init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath*:spring-*.xml</param-value>
        </init-param>不加classpath*也容易报404,

然后解决了404的问题,500的问题又来了,

Error creating bean with name 'sqlSessionFactory' defined in file [xxxxxxx]

Initialization of bean failed; nested exception is org.springframework.beans.77peMismatchException: 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 [xxxxx]:

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 [xxxxxxxxxx]: class path resource [xxxxxxxxxx] cannot be resolved to URL because it does not exist

然后在网上各种找资料,https://blog.csdn.net/weixin_41327789/article/details/80741755解决了我上面的问题,

然后它又报了新的错误

Error creating bean with name 'userController': 
Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 

class path resource [conf/jdbc.properties] cannot be opened because it does not exist  我在src/main/resources文件夹下新建了一个conf文件夹,然后<context:property-placeholder location="classpath:/conf/jdbc.properties" /> 这个错误也没报了,不知道有没有解决。到此我在controller层方法里写的输出语句已经可以打印了,很兴奋!

目前,最新的错误是Invalid bound statement (not found): top.bluehair.dao.UserDao.login,等待更新< _>

猜你喜欢

转载自blog.csdn.net/qq_37785777/article/details/81191720