2015-12-03 36 views
0

我要创建与数据库的连接在Spring MVC中插入特定的值,但有以下错误在我的servlet-context.xml中,同时创建连接:Spring MVC的数据库连接

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'什么意思

“匹配通配符是严格的”

这里是调度员的代码。提前致谢。

<?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> 
+0

请提供更多代码。 “dataSource”可能存在问题 –

+0

bean id = dataSource行有错误。 – Rohit

+0

什么类型的错误? –

回答

0

OK,所以问题是,你没有为豆指定通配符,所以你应该写:

<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> 

,然后应该工作。

+0

感谢m.aibin现在错误消失了。请问我是否知道问题是什么,如果你知道Spring MVC的任何好门户,而不是建议我,因为我已经通过spring.io文档,但错误没有点击给我。 – Rohit

+0

基础知识:http://www.mkyong.com/tutorials/spring-mvc-tutorials/ - 但要小心,一些答案很旧。比谷歌和spring.io;)请检查框中的正确答案;) –

+1

再次感谢我学习解析从Mkyong教程,我也通过spring.io以及。 – Rohit