Announcement Announcement Module
Collapse
No announcement yet.
no declaration can be found for element 'tx:annotation-driven Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • no declaration can be found for element 'tx:annotation-driven

    Help please

    In the midst of a project were most all was working with the hibernateTemplate. Then reading that new projects should use the Hibernate3 API and not the hibernateTemplate, so I decided to eliminate it. When I add the "<tx:annotation-driven />" attribute to my Spring config file I get the following:

    Code:
    INFO: Loading XML bean definitions from class path resource [springBeans.xml]
    Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 24 in XML document from class path resource [springBeans.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven'.
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:389)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:327)
    ...
    Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven'.
    	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
    	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
    I have seen the error mentioned here several times none of the solutions fit or resolve my problem. I have cut my project to the absolute minimum for testing purposes.

    Jar files included: derbyclient.jar (10.5), spring.jar (2.5.6), commons-dbcp.jar, commons-logging.jar, commons-pool.jar. All from the Spring with dependencies distribution. Java 1.6.

    My Spring config file "springBeans.xml" is:
    Code:
    <?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:tx="http://www.springframwork.org/schema/tx"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans 
    		http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    		http://www.springframework.org/schema/tx
    		http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
    
    	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    		<property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver" />
    		<property name="url"
    			value="jdbc:derby://localhost:1527/LessonDB;create=true" />
    		<property name="username" value="app" />
    		<property name="password" value="app" />
    		<property name="initialSize" value="2" />
    		<property name="maxActive" value="5" />
    	</bean>
    	<bean id="jdbcCourseDAO" 
    		class="examples.JdbcCourseDAOImpl">
    		<property name="dataSource" ref="dataSource" />
    	</bean>
    
    	<tx:annotation-driven />
    
    	<bean id="transactionManager"
    		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    		<property name="dataSource" ref="dataSource" />
    	</bean>	
    </beans>
    Domain Class:
    Code:
    package examples;
    
    public class CourseT {
    	private Long id;
    	private String meetWkDays;		
    	private String poolArea;
    	private Integer version;
    
    	public CourseT(Long id, String poolArea) {
    		super();
    		this.id = id;
    		this.poolArea = poolArea;
    	}
    
    	public String getMeetWkDays() {
    		return meetWkDays;
    	}
    
    	public void setMeetWkDays(String meetWkDays) {
    		this.meetWkDays = meetWkDays;
    	}
    
    	public Long getId() {
    		return id;
    	}
    
    	public void setId(Long id) {
    		this.id = id;
    	}
    
    	public String getPoolArea() {
    		return poolArea;
    	}
    
    	public void setPoolArea(String poolArea) {
    		this.poolArea = poolArea;
    	}
    
    	public Integer getVersion() {
    		return version;
    	}
    
    	public void setVersion(Integer version) {
    		this.version = version;
    	}
    }
    DAO Class:
    Code:
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    
    import javax.sql.DataSource;
    
    public class JdbcCourseDAOImpl implements JdbcCourseDAO {
    	private DataSource dataSource;
    
    	public void setDataSource(DataSource dataSource) {
    		this.dataSource = dataSource;
    	}
    
    	public CourseT findAllCourses() {
    		String sql = "Select * From Course where id = ?";
    		Connection conn = null;
    		try {
    			conn = dataSource.getConnection();
    			PreparedStatement ps = conn.prepareStatement(sql);
    			ps.setLong(1, 11L);
    			CourseT courseT = null;
    			ResultSet rs = ps.executeQuery();
    			if (rs.next()) {
    				courseT = new CourseT(rs.getLong("ID"), rs
    						.getString("POOL_AREA"));
    			}
    			rs.close();
    			ps.close();
    			return courseT;
    
    		} catch (SQLException sqle) {
    			System.out.println("didn't work " + sqle.getMessage());
    		} finally {
    			if (conn != null) {
    				try {
    					conn.close();
    				} catch (SQLException sqle) {
    					System.out.println("conn not closed " + sqle.getMessage());
    				}
    			}
    		}
    		return null;
    	}
    }
    Testing Class:
    Code:
    package examples;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class Main {
    
    	public static void main(String[] args) {
    		ApplicationContext context = new ClassPathXmlApplicationContext(
    				"springBeans.xml");
    		JdbcCourseDAOImpl dao = (JdbcCourseDAOImpl) context.getBean("jdbcCourseDAO");
    		
    		CourseT t = dao.findAllCourses();
    		System.out.println("here some stuff " + t.getPoolArea());
    
    	}
    }
    Any guidance would be greatly appreciated. Thank you.

  • #2
    Problem found, or Fixed

    In reality, spelling is a beautiful thing, I wish I could do it. My xmlns:tx="http://www.springframwork.org/schema/tx" should have been xmlns:tx="http://www.springframework.org/schema/tx". Adding the "e" to springframework made all the difference.

    Have a good day
    Last edited by rusty.hinge; Nov 1st, 2009, 11:14 AM.

    Comment

    Working...
    X