<jdbc:intégré-base de données> dans context.xml ne fonctionne pas. Souhaitez démarrer un script sql pour les tests unitaires
Voici mon fichier de contexte.:
<beans default-lazy-init="true" xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"> <!--Line 11-->
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <!---->
<property name="driverClassName" value="org.hsqldb.jdbc.JDBCDriver"/>
<property name="url" value="jdbc:hsqldb:mem:mydb"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="hibernate.cfg.xml.incDTD"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.connection.shutdown">true</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<jdbc:embedded-database id="embedded" type="HSQL"/>
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="classpath:ctl_data-scrubd.sql"/>
</jdbc:initialize-database>
J'obtiens cette erreur
Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 11 in XML document from class path resource [PersistenceHelper-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 11; columnNumber: 64; <Line 11, Column 64>: XML-24500: (Error) Can not build schema 'http://www.springframework.org/schema/jdbc' located at 'http://www.springframework.org/schema/jdbc/spring-jdbc.xsd'
Je veux lancer un script sql pour les tests. J'ai besoin de démarrer à partir de l'intérieur de ce fichier xml. J'ai lu l'aide en cela ne fonctionne pas. Personne ne sait comment je peux résoudre ce problème, ou une autre façon de démarrer une .fichier sql à partir de l'intérieur. Si vous souhaitez voir plus de mon code, s'il vous plaît laissez-moi savoir.
Edit::
J'ai posté la même question sur un autre site, et j'ai quelques suggestions. L'erreur est maintenant:
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.jdbc.datasource.init.DataSourceInitializer#0': Invocation of init method failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: Failed to execute database script; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement at line 1 of resource class path resource []: bin
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean
Voici mon fichier de config maintenant. Je me suis contenté d'ajouter une version et placer certains des déclarations autour de:
<?xml version="1.0" encoding="UTF-8"?>
<!-This is the spring configuration file for test cases.-->
<beans default-lazy-init="true" xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">
<tx:annotation-driven transaction-manager="transactionManager"/>
Tout le reste est le même.
OriginalL'auteur nook | 2012-06-21
Vous devez vous connecter pour publier un commentaire.
Juste pour compléter les réponses, c'est le contexte qui fonctionne pour moi (Printemps 3.2.1):
Merci!!!!! quand j'ai ajouté : xmlns:jdbc="springframework.org/schema/jdbc" xsi:schemaLocation="springframework.org/schema/beans springframework.org/schema/beans/spring-beans-4.0.xsd springframework.org/schema/jdbc springframework.org/schema/jdbc/spring-jdbc-4.0.xsd springframework.org/schema/mvc springframework.org/schema/mvc/spring-mvc-4.0.xsd springframework.org/schema/context springframework.org/schema/context/spring-context-4.0.xsd" il a travaillé !! merci!!!!!!
OriginalL'auteur Xtreme Biker
Fixe en déplaçant la définition xmlns:jdbc="http://www.springframework.org/schema/jdbc" pour le haut et par l'ajout d'un numéro de version "printemps-jdbc 3.0.xsd" à la définition.
OriginalL'auteur nook
Pouvez-vous confirmer que vous avez le printemps-jdbc jar dans le classpath
Oh, d'accord, donc vous avez été absent de la
<?xml version="1.0" encoding="UTF-8"?>
, j'avais supposé que vous l'aviez en vous démontrant un extrait de sans la partie supérieure. Au sujet de votre nouvelle question - je pense que c'est parce qu'il ya quelque chose de mal avec le contenu de votre fichier de script sql. Un autre problème que je vois est que vous avez nommé votre incorporé source de données 'embedded' mais votre intializer est en cours d'exécution à l'encontre d'une source de données appelédatasource
, est-ce correct, idéalement, vous voulez exécuter le script sur la source de données intégré seul droit?Je doute fortement qu'il est de mon script sql, parce qu'il a été exécuté de nombreuses fois avant, j'ai commencé à introduire le framework spring dans notre programme. Pourriez-vous expliquer ce que vous entendez par la deuxième partie? Ma source de données détient les valeurs appropriées de mise en veille prolongée la base de données pour le créer ("je veux utiliser le mot schéma ici, mais je ne suis pas complètement sûr si c'est ce qu'il est"). Sql script a les valeurs à insérer dans les tables. Idéalement, je veux créer la table, puis exécutez le script sur la table pour la remplir, si cela fait sens.
OriginalL'auteur Biju Kunjummen