最近因为毕业设计匆忙学习了SSM框架,在看了各种资料后真心推荐B站的DT课堂的颜群老师的视频,适合有一定计算机基础但又没学习过servlet和ssm框架的人群
使用spring tool suite4开发web项目时,发现没有spring bean configuration file,并且生成的web.xml中显示
1 referenced file contains errors (http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd). For more information, right
click on the message in the Problems View and select "Show Details..."
2 web.xml中还显示<display-name>错误,显示invalid element
先解决没有spring bean configuration file的问题,在网上找了两个解决方案
一
如上图所示,但因为spring roo的下载速度实在是太慢了,于是我重新下载了spring tool suite3
下载地址:https://github.com/spring-projects/toolsuite-distribution/wiki/Spring-Tool-Suite-3
安装了sts3之后,发现有了spring bean configuration file,并且之前提醒的referenced file contains errors(http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd)也不见了
安装sts3之后,记得重新部署tomcat和修改默认编码方式为UTF-8(Window-->Preferences--->General-->Workspace”,Eclipse默认GBK编码,选中“Other”,切换UTF-8)如果要单独修改项目的编码方式,则右键Properties-->Resource,右边栏中选中“Other”,切换编码为UTF-8
referenced file contains errors错误可以修改
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID"
version="2.5">
将javaee改成java2e,再进行保存,错误就不见了
在用sts3进行开发后,又遇到了问题
用全局配置mapper文件后
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
<property name="basePackage" value="org.cc.mapper"></property>
在applicationContext.xml中中为service注入mapper(dao)
<!-- 依赖注入:给service注入dao -->
<bean id="userService" class="org.cc.service.impl.UserServiceImpl">
<property name="userMapper" ref="userMapper"></property>
</bean>
后显示错误Multiple annotations found at this line:
- Referenced bean 'userMapper' not found
- No setter found for property 'userMapper' in class
但我明明在UserServiceImpl文件中写了setter,也全局配置了mapper。
最后将环境换到spring tool suite4中,同样的代码,就没有错误了