Java 无法解析bean driverClassName
当我创建一个Spring配置xml时,我在添加数据源时遇到了一个错误,它说无法解析bean 我的Java 无法解析bean driverClassName,java,spring,Java,Spring,当我创建一个Spring配置xml时,我在添加数据源时遇到了一个错误,它说无法解析bean 我的spring.xml是: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context
spring.xml
是:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.dqbz" />
<!-- 配置整合mybatis过程 -->
<!-- 1.配置数据库相关参数properties的属性:${url} -->
<context:property-placeholder location="classpath:jdbc.properties" />
<!-- 2.数据库连接池 -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<!-- 基本属性driverClassName、 url、user、password -->
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
</beans>
您是否尝试从bean定义中删除以下注释
<!-- 基本属性driverClassName、 url、user、password -->
这应该是一个评论,因此它没有回答问题。我很高兴你这么快就得出结论@YassinHajaj。在查看配置时,我看不到其他问题——根据帖子的标题,它抱怨一个名为“drivercassname”的bean。评论中还有中文字符。谁知道它是如何被解析的。只要文档的其余部分在语义上是正确的,XML并不真正关心您将注释粘贴到何处。此外,出于启发,我还可以复制OP的问题,即使我键入了属性。无法复制此问题。我完全按照帖子的要求复制到STS中,没有发现任何问题。