Spring MVC数据库连接
我必须创建与数据库的连接以在Spring MVC中插入某些值,但在创建连接时,我的servlet-context.xml中存在以下错误:Spring MVC数据库连接,spring,jsp,spring-mvc,spring-jdbc,Spring,Jsp,Spring Mvc,Spring Jdbc,我必须创建与数据库的连接以在Spring MVC中插入某些值,但在创建连接时,我的servlet-context.xml中存在以下错误: Multiple annotations found at this line: - Cannot locate BeanDefinitionParser for element [bean] - cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be
Multiple annotations found at this line: - Cannot locate BeanDefinitionParser for element [bean] - cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'bean'. - Configuration problem: Cannot locate BeanDefinitionParser for element [bean] Offending resource: file [E:/General Workspace/Spring Workspace/Record_mvc/ src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml]
我已经用id=“dataSource”
声明了bean,但它似乎不起作用。您能帮助我理解为什么它找不到元素'bean'
的声明,以及它的含义吗
“匹配的通配符是严格的”
这是dispatcher的代码。提前谢谢
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
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">
<!-- DispatcherServlet Context: defines this servlet's request-processing
infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving
up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources
in the /WEB-INF/views directory -->
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="com.lead.mvc" />
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:8080/leadmanager" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
<!-- <bean id="jdbcTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean> -->
</beans:beans>
好的,问题是您没有为bean指定通配符,所以您应该写:
<beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:8080/leadmanager" />
<property name="username" value="root" />
<property name="password" value="root" />
</beans:bean>
然后是应该工作。请提供更多代码。“dataSource”可能有问题bean id=dataSource的第行有错误。在该行找到多个批注:-找不到元素[bean]的BeanDefinitionParser]-cvc复杂类型。2.4.c:匹配的通配符很严格,但找不到元素“bean”的声明。-配置问题:找不到元素[bean]的BeanDefinitionParser有问题的资源:文件[E:/General Workspace/Spring Workspace/Record\u mvc/src/main/webapp/WEB-INF/Spring/appServlet/servlet context.xml]检查谢谢m.aibin错误现在消失了。我可以知道问题出在哪里吗?如果你知道Spring MVC有什么好的门户网站,那就建议我吧,因为我已经通过了Spring.io文档,但是我没有注意到错误。基本知识:-但是要小心,有些答案很旧。比谷歌和spring.io;)请勾选框以获得正确答案;)再次感谢您,我已经从Mkyong教程中学习了语法分析,我也学习了spring.io。