I have a database project which is using spring. For that I have two important files in src/META-INF/spring/(database project)
The first one is the cmn-dao-spring.xml . The other one is the database.properties.
In my tomcat webapp project I am able to load with that code all the needed context-files:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:/META-INF/spring/*.xml
</param-value>
</context-param>
The problem is that the database.properties is not loaded.
If I change the xml to this:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:/META-INF/spring/*
</param-value>
</context-param>
I get the Exception:
Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog.
because the properties is no valid xml.
The startup of my tomcat fails.
How can I include the database.properties from my cmn-dao project in my webapp?
EDIT
That is my cmn-dao.xml:
<?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:context="http://www.springframework.org/schema/context"
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/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<tx:annotation-driven />
<context:annotation-config />
<!-- DATABASE CONFIGURATION -->
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>META-INF/spring/database.properties</value>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- BEAN DEFINITIONS -->
<bean id="scoreMapper" class="de.bc.qz.dao.mapper.ScoreMapper"
autowire="byName">
<constructor-arg value="s." />
</bean>
<bean id="scoreExtractor" class="de.bc.qz.dao.extractor.ScoreExtractor"
autowire="byName">
</bean>
<bean id="questionMapper" class="de.bc.qz.dao.mapper.QuestionMapper"
autowire="byName">
<constructor-arg value="q." />
</bean>
<bean id="complaintMapper" class="de.bc.qz.dao.mapper.ComplaintMapper"
autowire="byName">
<constructor-arg value="c." />
</bean>
<bean id="scoreDao" class="de.bc.qz.dao.ScoreDao" autowire="byName">
<property name="dataSource" ref="dataSource" />
<property name="LAUSFT">
<value>
SELECT * FROM (
SELECT s.*, #rank
:= #rank + 1 rank
FROM
quiz.score s, (SELECT #rank := 0) init
ORDER BY points DESC
) s
WHERE rank BETWEEN ? AND ?
ORDER BY rank;
</value>
</property>
<property name="LUS">
<value>
SELECT id
FROM quiz.score
WHERE username = ? AND uuid = ?;
</value>
</property>
</bean>
<bean id="complaintDao" class="de.bc.qz.dao.ComplaintDao"
autowire="byName">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="questionDao" class="de.bc.qz.dao.QuestionDao" autowire="byName">
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
The JUnit's for cmn-dao works absolut correct and the placeholder works too.
Inside tomcat project I have added the related projects via Deployment Assembly.
Thx for your help
Stefan
use spring util to read properties file.
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="
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
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
<context:annotation-config />
<util:properties id="db_config" location="classpath:db_config.properties"></util:properties>
</beans>
user spring new '#value' annotation to get the property file key=value i.e
example : db_config.properties contains
db_user_name = uttesh
db_password = password
to get "db.user.name" property value use below code
#Value("#{db_config[db_user_name]}")
private String dbUsername;
contextCongifLocation is for spring configuration files only.
use this in your spring config (xml) file for loading properties:
<bean id="props" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:META-INF/spring/database.properties"/>
</bean>
or
<context:property-placeholder location="classpath:META-INF/spring/database.properties" />
Try to use the util namespace instead, it allows to load several property files and separate them into property groups:
<util:properties id="application" location="classpath:application.properties"/>
To use the properties:
<bean id="postgresDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="#{application.driverClassName}"/>
<property name="url" value="#{application.url}"/>
<property name="username" value="#{application.username}"/>
<property name="password" value="#{application.password}"/>
</bean>
This is the properties file example:
driverClassName=org.postgresql.Driver
url=jdbc:postgresql://localhost:5432/somedatabase
username=dummy
password=dummy
Change your context file to something like that :
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:/META-INF/spring/*.properties
</param-value>
</context-param>
Use contextConfigLocation in web.xml to read your main spring config xml file.
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/META-INF/spring/spring-app-context.xml
</param-value>
</context-param>
import cmn-dao.xml in spring-app-context.xml
<import resource="classpath:/META-INF/spring/cmn-dao.xml" />
Now use PropertyPlaceholderConfigurer to read database.properties in cmn-dao.xml
<bean id="props" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:META-INF/spring/database.properties"/>
</bean>
This is how you load property files into your spring context:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<context:property-placeholder location="classpath*:META-INF/spring/*.properties"/>
</beans>
Related
I need to load datasource properties from properties file
db.properties:
url = my_url
user = user_name
password = user_pass
this is dataSource (camelcontext.xml):
I'm trying like this, it is not working.
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:db.properties"/> </bean>
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
<property name="URL" value="${url}"/>
<property name="user" value="${user}"/>
<property name="password" value="${pasword}"/>
</bean>
My routes are implemented in java dsl.
In order to use Camel Properties in Spring XML, you have to add the following Spring bean with the ID 'properties'
<bean id="properties"
class="org.apache.camel.component.properties.PropertiesComponent">
<property name="location" value="classpath:db.properties"/>
</bean>
OR (after your comment please try this):
<?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:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
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
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
<property name="URL" value="${url}"/>
<property name="user" value="${user}"/>
<property name="password" value="${pasword}"/>
</bean>
<context:property-placeholder properties-ref="properties"/>
<util:properties id="properties" location="classpath:db.properties"/>
url = my_url
property name="URL" value="${url}"
When using the expression language like ${...} you have to reference the keys of your property file, not the values. You propably want to write s.th. like
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
<property name="URL" value="${url}"/>
<property name="user" value="${user}"/>
<property name="password" value="${password}"/>
</bean>
I am trying to import a standard spring project P1 into a web project P2 and I am implementing the web aspect of P1 in P2.
I have imported all resources of P1 in P2 as P1.jar
Have explicitly imported the application context file as well using <import-resource> which happens successfully.
But the JpaRepositories does not get autowired in P2. It doesn't seem to be in the context of P2.
Can anyone suggest what I might be missing here.
UPDATE: 25Nov2016
P1-ApplicationContext.xml
<?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:context="http://www.springframework.org/schema/context"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:repository="http://www.springframework.org/schema/data/repository"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.8.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository-1.11.xsd">
<tx:annotation-driven proxy-target-class="true"/>
<context:component-scan base-package="com.home.p1.blog" />
<jpa:repositories base-package="com.home.p1.blog.repo" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver" />
<property name="url"
value="jdbc:derby://localhost:1527/MyDerby" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="WorkUp" />
<property name="dataSource" ref="dataSource"></property>
<property name="packagesToScan" value="com.home.p1.blog"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="org.hibernate.dialect.DerbyDialect" />
</bean>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.DerbyDialect</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.use_sql_comments">false</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="authorDAO" class="com.home.p1.blog.repo.AuthorDAO">
</bean>
<bean id="authorService" class="com.home.p1.blog.service.AuthorServiceImpl"></bean>
<bean id="blogService" class="com.home.p1.blog.service.BlogServiceImpl"></bean>
</beans>
P2-ApplicationContext.xml (its actually named: rest-servlet.xml to hold the RestController scan package)
<?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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:repository="http://www.springframework.org/schema/data/repository"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.8.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository-1.11.xsd">
<import resource="classpath:com.home.p1.blog.src/src/main/resources/P1-ApplicationContext.xml"/> <!-- this loads find -->
<context:component-scan base-package="com.home.p2.blog.controller" /> <!-- this will load the RestController -->
<!-- <context:component-scan base-package="com.home.**" /> -->
<!-- THIS GIVES SOME WIERD ERROR <jpa:repositories base-package="com.home.*" /> -->
<mvc:annotation-driven/>
<!-- <bean id="blogService" class="com.oracle.blog.service.BlogServiceImpl"></bean> -->
</beans>
UPDATE: 28Nov2016
Upon including <jpa:repositories base-package> configuration in P2's application context, I no longer get the wierd error which I was getting earlier.
Also, enabling a successful import of xml config in Spring bean support, everything else is falling appropriately into place. Only the JpaRepositories referred in P1 are not reflecting in P2's context.
I dont think what you are trying to do is possible. You need to enable repository scan in your p2 and mention the packages in that scan.
If your p1.jar is in the classpath of p2 then you only have enable repository scan in your p2,
<jpa:repositories base-package="com.home.p1.blog.repo" />
RESOLVED: Please note that to import the JpaRepositories from P1.jar in P2, we don't have to mention <jpa:repositories> tag in P2's config xml.
Just ensure that we are appropriately importing the P1's config.xml.
Also Eclipse users need to add Xml / Java config in Spring Beans Support tab as well as enable support for import element.
I searched for how to configure spring with tomcat I found that I have to put the following loader into context
<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
And I have to put spring-instrument-tomcat-x.x.jar into the tomcat lib folder
applicationContext.xml
<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<import resource="database-mysql.xml" />
<context:load-time-weaver aspectj-weaving="off" />
<!-- enables interpretation of the #Resource annotation to apply dependency injection through annotations -->
<context:component-scan base-package="com.shs.dao"></context:component-scan>
<context:component-scan base-package="com.shs.service"></context:component-scan>
<context:component-scan base-package="com.shs.web"></context:component-scan>
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"/>
<!-- enables interpretation of the #PersistenceUnit/#PersistenceContext annotations providing convenient
access to EntityManagerFactory/EntityManager -->
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<bean id="contextApplicationContextProvider" class="com.shs.utils.spring.AppContext"></bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="Default_Persistence_Unit"/>
<property name="dataSource" ref="dataSource"/>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="false"/>
<property name="database" value="MYSQL"/>
</bean>
</property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver"/>
</property>
</bean>
<bean id="jpaTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:annotation-driven transaction-manager="jpaTransactionManager" proxy-target-class="true"/>
</beans>
But I know there is another methodology to configure spring without using context loader or putting the jar into tomcat lib folder
Any ideas how to do that
Thanks in advance
An exception occurs while I'm trying to persist an object.
import org.springframework.transaction.annotation.Transactional;
#Repository("DBRepository")
#Transactional
public class DBRepository implements Repository {
#PersistenceContext
private EntityManager entityManager;
#Override
public void addElement(Element element) {
logger.debug("Element {} is going to be added to database", element);
entityManager.persist(element);
}
}
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="p_unit" transaction-type="RESOURCE_LOCAL"/>
</persistence>
web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/jpa-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
jpa-config.xml
<?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.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="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-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<!-- Using annotation to configure application -->
<context:annotation-config/>
<context:component-scan base-package="web.tmh"/>
<!-- Tells Spring to use persistence context annotation -->
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<tx:annotation-driven mode="proxy" transaction-manager="transactionManager"/>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="p_unit"/>
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true"/>
</bean>
</property>
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<entry key="hibernate.hbm2ddl.auto" value="update"/>
</map>
</property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<!-- autoReconnect=true param allows our application to reconnect to base if connection was lost -->
<property name="url" value="jdbc:mysql://localhost:3306/TellMeHow?autoReconnect=true"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
</beans>
So as you can see I used right Transactional annotation, and have <tx:annotation-driven mode="proxy" transaction-manager="transactionManager"/>in my jpa-config.xml. So I don't really understand why it doesn't want do work
Ok, the problem was solved. I've made a small mistake in my dispatcher-config.xml:
So instead of
<mvc:annotation-driven/>
<context:component-scan base-package="web.tmh"/>
I had to write
<mvc:annotation-driven/>
<context:component-scan base-package="web.tmh.controller"/>
I thought that component-scan worked recursively, but seems like it didn't...
I'm training myself with spring and mybatis exercises.
I'm trying to solve these two errors since yesterday:
1)
Description Resource Path Location Type cvc-complex-type.2.4.c: The
matching wildcard is strict, but no declaration can be found for
element
'context:annotation-config'. ApplicationContext.xml /Example/WebContent/WEB-INF line
14 XML Problem
for these lines:
<context:component-scan base-package="Controller" />
<context:component-scan base-package="service"/>
<context:component-scan base-package="test.dao.samp"/>
<context:component-scan base-package="test.model.samp"/>
and this:
2)
Description Resource Path Location Type
schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/context/spring-context-4.0.xsd',
because 1) could not find the document; 2) the document could not be
read; 3) the root element of the document is not
. ApplicationContext.xml /Exemple/WebContent/WEB-INF line
14 XML Problem
schema_reference.4: Failed to read schema document
'http://www.springframework.org/schema/tx/spring-tx-4.0.xsd', because
1) could not find the document; 2) the document could not be read; 3)
the root element of the document is not
. ApplicationContext.xml /Exemple/WebContent/WEB-INF line
51 XML Problem
Here is my ApplicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:annotation-config/>
<context:component-scan base-package="Controller" />
<context:component-scan base-package="service"/>
<context:component-scan base-package="test.dao.samp"/>
<context:component-scan base-package="test.model.samp"/>
<bean id='dataSource'
class='org.springframework.jdbc.datasource.SimpleDriverDataSource'>
<property name='driverClass' value='org.apache.derby.jdbc.EmbeddedDriver' />
<property name='url'
value='jdbc:derby:C:\Users\XXX\IBM\rationalsdp\workspace\.metadata\.plugins\com.ibm.datatools.db2.cloudscape.driver\SAMPLE;create=true' />
<property name='username' value='admin' />
<property name='password' value='admin' />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="WEB-INF\psaIbatisConf.xml" />
</bean>
<bean id="sqlMapClient" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg ref="sqlSessionFactory" />
</bean>
<!-- TRANSACTION MANAGER -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- ANNOTATION DRIVEN TRANSACTIONS -->
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
How I have understood, the errors come from the wrong xsd declaration, but I checked them a lot of times.
The jars I'm using are all 4.0.4 version.
I'm using RAD, Websphere, spring e myBatis with myBatis generator.
Edit:
I changed the version schema in the beans tag in this way:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
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/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
The firsts errors has disappeared, but the last one (line 51) remained.
take a look at this example of contex, maybe can help you. I use the same transaction manager.
<?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:jee="http://www.springframework.org/schema/jee"
xmlns:util="http://www.springframework.org/schema/util" xmlns:mockito="http://www.mockito.org/spring/mockito"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.mockito.org/spring/mockito https://bitbucket.org/kubek2k/springockito/raw/tip/springockito/src/main/resources/spring/mockito.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-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/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-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-2.5.xsd">
<context:annotation-config />
<tx:annotation-driven/>
<context:component-scan base-package="cat.base.gpt.logica" />
<import resource="classpath:tip-appConfiguration.xml" />
<bean id="gptServei" class="cat.base.gpt.logica.serveis.impl.ServeiGpt">
<property name="serveiSubjecte" ref="serveiSubjecte"/>
<property name="vwGptVBasicDAO" ref="vwGptVBasicDAO" />
<property name="vwGptVExpMSDAO" ref="vwGptVExpMSDAO" />
<property name="vwGptVObjectesBasicDAO" ref = "vwGptVObjectesBasicDAO"/>
<!--
Propietat per falicilitar el filtratge cat.base.gpt.multiens
true:Recuperem tots els ens
false: filtrem per ens
-->
<property name="filtratgeEns" value="${cat.base.gpt.multiens}"/>
<qualifier type="cat.base.gpt.domini.serveis.IServeiGpt" value="gptServei" />
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="connexioJdbctemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
<constructor-arg type="javax.sql.DataSource" ref="dataSource"/>
</bean>
<bean id="preparadorJdbctemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg type="javax.sql.DataSource" ref="dataSource"/>
</bean>
<bean id="vwGptVBasicDAO" class="cat.base.gpt.logica.dao.impl.VwGptVBasicDao">
<property name="template" ref="connexioJdbctemplate" />
</bean>
<bean id="vwGptVExpMSDAO" class="cat.base.gpt.logica.dao.impl.VwGptExpMSDao">
<property name="template" ref="connexioJdbctemplate" />
</bean>
<!-- DAO referent a objectes bĂ sics -->
<bean id="vwGptVObjectesBasicDAO" class="cat.base.gpt.logica.dao.impl.VwGptObjecteBasicDao">
<property name="template" ref="connexioJdbctemplate" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${cat.base.gpt.driverClassName}" />
<property name="url" value="${cat.base.gpt.url}" />
<property name="username" value="${cat.base.gpt.username}"/>
<property name="password" value="${cat.base.gpt.password}"/>
</bean>
<bean id="postprocess" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:cat/base/gpt/serveis/impl/logica.properties</value>
<value>classpath*:entorn-servidor.properties</value>
</list>
</property>
<property name="ignoreResourceNotFound" value="false" />
</bean>
</beans>
I solved the error importing the spring-tx library, precisely spring-tx-4.0.4.RELEASE.
By mistake I didn't check if there was the jar in lib folder.