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
Related
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 am working on a Spring MVC app. Running app on Jboss shows following error:
java.lang.NoSuchMethodError: org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.addAnnotatedClass(Ljava/lang/Class;)Lorg/hibernate/cfg/Configuration;
But I have all jars in WEB-INF/lib directory. I have included following jars:
antlr-3.1.1.jar
antlr-runtime-3.1.jar
aopalliance-1.0.0.jar
dom4j.jar
hibernate-commons-annotations-4.0.2.Final.jar
hibernate-core-4.2.16.Final.jar
hibernate-entitymanager-4.2.16.Final.jar
hibernate-envers-4.2.16.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
hibernate-validator-4.0.2.GA.jar
jackson-core-asl-1.9.7.jar
jackson-mapper-asl-1.9.7.jar
javassist-3.18.1-GA.jar
jboss-servlet-api_3.1_spec-1.0.0.Final.jar
json-simple-1.1.1.jar
jstl-1.2.jar
logback-classic-1.1.2.jar
logback-core-1.1.2.jar
slf4j-api-1.7.9.jar
spring-aop-4.0.0.RELEASE.jar
spring-aspects-4.0.0.RELEASE.jar
spring-beans-4.0.0.RELEASE.jar
spring-build-src-4.0.0.RELEASE.jar
spring-context-4.0.0.RELEASE.jar
spring-context-support-4.0.0.RELEASE.jar
spring-core-4.0.0.RELEASE.jar
spring-expression-4.0.0.RELEASE.jar
spring-framework-bom-4.0.0.RELEASE.jar
spring-instrument-4.0.0.RELEASE.jar
spring-jdbc-4.0.0.RELEASE.jar
spring-jms-4.0.0.RELEASE.jar
spring-messaging-4.0.0.RELEASE.jar
spring-orm-4.0.0.RELEASE.jar
spring-oxm-4.0.0.RELEASE.jar
spring-test-4.0.0.RELEASE.jar
spring-tx-4.0.0.RELEASE.jar
spring-web-4.0.0.RELEASE.jar
spring-webmvc-4.0.0.RELEASE.jar
spring-webmvc-portlet-4.0.0.RELEASE.jar
spring-websocket-4.0.0.RELEASE.jar
Following is my dispatcher servlet 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:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/resources/" />
<context:component-scan base-package="com.example.scm" />
<tx:annotation-driven/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean id="jndiDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:/MySqlDS" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="jndiDataSource" />
<property name="packagesToScan" value="com.example.scm"></property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
Can anybody please suggest some solution?
I am having trouble configuring JPA global type mappings via the package-info.java file, which looks like this:
#TypeDefs({
#TypeDef(
typeClass = MyCustomUserType.class,
defaultForType = MyType.class
)
})
package my.entity.package;
import...
My spring configuration file looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
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/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<context:spring-configured />
<context:annotation-config />
<context:component-scan base-package="my.package"/>
<context:property-placeholder location="classpath:/my.properties" />
<bean id="testDataSource" class="org.apache.commons.dbcp.BasicDataSource"
p:driverClassName="com.ibm.db2.jcc.DB2Driver"
p:url="jdbc:db2://${database.host}:50000/${database.dbname}:currentSchema=I0071DBA;"
p:username="${database.username}"
p:password="${database.password}"
p:initialSize="5"
p:maxActive="10">
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="testDataSource" />
<property name="persistenceProviderClass" value="org.hibernate.jpa.HibernatePersistenceProvider"/>
<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.DB2Dialect"/>
<entry key="hibernate.default_schema" value="MySchema"/>
<entry key="hibernate.cache.use_query_cache" value="false"/>
<entry key="hibernate.cache.use_second_level_cache" value="false"/>
</map>
</property>
<property name="packagesToScan" value="my.entity.package"/>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
I believe the packagesToScan property is being used, because all my entity classes are configured into the EntityManagerFactory. Only the package-info.java file is not being used. Any suggestions for configuring the package-info.java file into the EntityManagerFactory?
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.
I have following code:
//preparing DAO objects
FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext("test-context.xml");
surveyDao = (SurveyDao)context.getBean("surveyDao");
recordDao = (RecordDao)context.getBean("recordDao");
//creating GUI
createWindow();
The problem is that it runs perfectly in Eclipse, but when I export it to executable jar it crashes with following
org.springframework.beans.factory.parsing.BeanDefinitionParsingException
unable to locate Spring NameSpaceHandler for XML schema namespace
[http://www.springframework.org/schema/tx]
Offending resource: file test-context.xml
test-context.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
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:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"
default-lazy-init="true"
default-autowire="byName">
<context:annotation-config/>
<!-- <bean id="applicationContextProvider" class="org.openforis.collect.context.ApplicationContextAwareImpl" /> -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="file:${user.dir}/dev.properties"/>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="${collect.devdb.url}"/>
<property name="username" value="${collect.devdb.username}" />
<property name="password" value="${collect.devdb.password}" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="surveyDao" class="org.openforis.collect.persistence.SurveyDao" init-method="init">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="logoDao" class="org.openforis.collect.persistence.LogoDao">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="recordDao" class="org.openforis.collect.persistence.RecordDao">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="taxonomyDao" class="org.openforis.collect.persistence.TaxonomyDao">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="taxonDao" class="org.openforis.collect.persistence.TaxonDao">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="dynamicTableDao" class="org.openforis.collect.persistence.DynamicTableDao">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="myTest" class="com.arbonaut.collcomm.main.MyTest" init-method="init" />
<!-- Managers -->
<bean id="recordManager" class="org.openforis.collect.manager.RecordManager" init-method="init" />
<bean id="surveyManager" class="org.openforis.collect.manager.SurveyManager" init-method="init" />
<!-- Expression Factory -->
<bean id="expressionFactory" class="org.openforis.idm.model.expression.ExpressionFactory" />
<bean id="validator" class="org.openforis.idm.metamodel.validation.Validator" />
<bean id="externalCodeListProvider" class="org.openforis.collect.persistence.DatabaseExternalCodeListProvider" />
<bean id="taxonVernacularNameDao" class="org.openforis.collect.persistence.TaxonVernacularNameDao">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- enables interpretation of the #Transactional annotations for declarative transaction management-->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
</beans>
Have you got the spring-tx jar on the classpath / rebundled into your executable jar?
spring-tx-3.1.0-RELEASE.jar contains the xsd http://www.springframework.org/schema/tx/spring-tx-3.1.xsd:
/org/springframework/transaction/config/spring-tx-3.1.xsd