自己刚开始学习SSM框架整合是遇到了很多问题,虽然在网上大部分都能查找到,但是每次都去查的话还是有点麻烦,故这里记录一下我遇到的问题,可能会不全,慢慢添加吧;
1、cvc-complex-type.2.3: Element 'beans' cannot have character [children],because the type's content type is element-only.
此问题是由于在beans中出现了不符合规范的代码,可能是复制粘贴代码时的空格,引号,中文等文本,我出现的问题是注释的中文不小心把后半部分注释"-->"删掉了。
解:仔细检查文本的格式和内容,如果问题持续的话就手动再敲一遍吧。。。
2、Invalid bean definition with name 'dataSource' defined in class path resource [spring-mybatis.xml].
这个问题根据描述就是无法创建dataSource这个bean,很大的可能是引入的db.properties文件引入错误
解:采用此方式引入配置文件<util:properties id="config" location="classpath:db.properties"></util:properties>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="#{config.driver}" />
<property name="url" value="#{config.url}" />
<property name="username" value="#{config.username}" />
<property name="password" value="#{config.password}" />
</bean>
value中的值名称要和db.properties中的名称一致。
3、Error creating bean with name 'userService': Injection of autowired dependencies failed;
这个问题是spring配置中的问题,在xml文件中注解扫描dao容器时路径设置错误
解:<context:component-scan base-package="路径"/>
路径部分填写仔细就可以解决。
4、Type interface com.mybatis.mapper.UserMapper is not known to the MapperRegistry.
这个问题是mybatis配置中mapper找不到注册信息的问题
解:在mybatis全局的配置文件中
<mappers>
<!--userMapper.xml装载进来 同等于把“dao”的实现装载进来 -->
<mapper resource="mappers/UserMapper.xml" />
<!-- <package name="mappers"/> -->
</mappers>
1.这里如果使用resource :正确填写路径就可以了;
2.如果使用package:则 mapper.xml和dao类要在同一个包下,且名称要一致。