XML : Spring sql database connecting error in xml

I just start learning spring. I was trying to fetch data from my data base using spring, but got exception from xml file. I dont know whats the issue, I searched alot but unable to fix it. Please help me out. Any help would be appreciated. Thanks in advance.

Main Class

  package com.spring.demo;    import org.springframework.context.ApplicationContext;  import org.springframework.context.support.ClassPathXmlApplicationContext;    public class MainApp {        @SuppressWarnings("resource")      public static void main(String[] args) {              ApplicationContext cntxt = new ClassPathXmlApplicationContext("spring.xml");          JdbcDaoImpl dao = cntxt.getBean("JdbcDaoImpl", JdbcDaoImpl.class);          UserModel model = dao.getUserName("admin");              model.display();     }  }    

DAO IMPLI

  package com.spring.demo;    import java.sql.Connection;  import java.sql.PreparedStatement;  import java.sql.ResultSet;  import java.sql.SQLException;    import javax.sql.DataSource;    import org.springframework.beans.factory.annotation.Autowired;  import org.springframework.stereotype.Component;  @Component  public class JdbcDaoImpl {      @Autowired      private DataSource dataSource;        public DataSource getDataSource() {          return dataSource;      }        public void setDataSource(DataSource dataSource) {          this.dataSource = dataSource;      }        public UserModel getUserName(String userName){          Connection con = null;            try{              con = dataSource.getConnection();              PreparedStatement ps = con.prepareStatement("select * from userinfo where userName = ?");              ps.setString(1, "vaibhav");              UserModel model = null;              ResultSet rs = ps.executeQuery();              if(rs.next()){                  model = new UserModel();                  model.setUserName(rs.getString("userName"));              }              rs.close();              ps.close();               return model;          }          catch(Exception e){              throw new RuntimeException(e);          }          finally{              try{                  con.close();              }              catch(SQLException s){                }          }      }        }    

SPRING.XML

  <?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:jdbc="http://www.springframework.org/schema/jdbc"      xmlns:context="http://www.springframework.org/schema/context"      xsi:schemaLocation="      http://www.springframework.org/schema/beans      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd      http://www.springframework.org/schema/aop      http://www.springframework.org/schema/aop/spring-aop-2.5.xsd      http://www.springframework.org/schema/tx      http://www.springframework.org/schema/tx/spring-tx-2.5.xsd      http://www.springframework.org/schema/context      http://www.springframework.org/schema/context/spring-context.xsd">     <context:annotation-config />     <context:component-scan base-package="com.spring.demo" />         <bean id ="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">     <property name="driverClassName" value="com.mysql.jdbc.Driver" />      <property name="url" value="jdbc:mysql://localhost:3306/testing" />     <property name="userName" value="vaibhav" />     <property name="password" value="bhopal@123" />     </bean>     </beans>    

Console

  Dec 05, 2015 12:10:16 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh  INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1c12fb0: startup date [Sat Dec 05 12:10:16 IST 2015]; root of context hierarchy  Dec 05, 2015 12:10:16 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions  INFO: Loading XML bean definitions from class path resource [spring.xml]  Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 20 in XML document from class path resource [spring.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 20; columnNumber: 69; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'property'.      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:399)      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:252)      at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)      at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)      at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)      at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:608)      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:509)      at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)      at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)      at com.spring.demo.MainApp.main(MainApp.java:12)  Caused by: org.xml.sax.SAXParseException; lineNumber: 20; columnNumber: 69; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'property'.      at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)      at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)      at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)      at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)      at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)      at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(Unknown Source)      at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(Unknown Source)      at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)      at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.emptyElement(Unknown Source)      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)      at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)      at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)      at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)      at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)      at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:76)      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:429)      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)      ... 14 more    

No comments:

Post a Comment