I am not able to resolve the issue am getting.
Full stacktrace:
12:14:08.172 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
12:14:08.178 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
12:14:08.178 [main] DEBUG o.s.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
12:14:08.183 [main] INFO o.s.c.s.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext#24273305: startup date [Thu Mar 16 12:14:08 GMT 2017]; root of context hierarchy
12:14:08.222 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
12:14:08.223 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
12:14:08.223 [main] DEBUG o.s.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
12:14:08.233 [main] INFO o.s.b.f.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [org/postprocessor/config/dataSupport.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [org/postprocessor/config/dataSupport.xml]; nested exception is java.io.FileNotFoundException: class path resource [org/postprocessor/config/dataSupport.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344)
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:612)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:513)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at org.postprocessor.dao.DaoMain.main(DaoMain.java:12)
Caused by: java.io.FileNotFoundException: class path resource [org/postprocessor/config/dataSupport.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330)
... 13 more
Bean config file dataSupport.xml is here:
<?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"
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">
<!-- <bean/> definitions here -->
<context:annotation-config />
<context:component-scan base-package="org.postprocessor.dao" />
<context:component-scan base-package="org.postprocessor.model" />
<context:component-scan base-package="org.postprocessor.util" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver"
/> <property name="url" value="jdbc:derby:postprocessor;create=true;" />
<!-- <property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver" />
<property name="url" value="jdbc:derby://localhost:1527/db;create=true;" /> -->
<property name="initialSize" value="1" />
<property name="maxActive" value="1" />
</bean>
<bean id="daoImpl" class="org.postprocessor.dao.DaoImpl" scope="prototype">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>resourceBundles/general</value>
<value>resourceBundles/codeLists/codelist_eortcqlqc30</value>
<value>resourceBundles/codeLists/codelist_eortcqlqlc13</value>
<value>resourceBundles/codeLists/codelist_eq5d3l</value>
<value>resourceBundles/codeLists/codelist_eq5d5l</value>
<value>resourceBundles/codeLists/codelist_noncompletedquestionnaires</value>
<value>resourceBundles/codeLists/codelist_pgis</value>
<value>resourceBundles/codeLists/codelist_silc</value>
</list>
</property>
</bean>
snipped from pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>SBP</groupId>
<artifactId>SBP</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>gt20047</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-asm -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
<version>3.1.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/asm/asm-all -->
<dependency>
<groupId>asm</groupId>
<artifactId>asm-all</artifactId>
<version>3.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.derby/derbynet -->
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbynet</artifactId>
<version>10.12.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.derby/derbyclient -->
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.12.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>2.0.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-dbcp/commons-dbcp -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-pool/commons-pool -->
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>3.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-io -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-collections/commons-collections -->
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
<build>
<finalName>gt20047</finalName>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3</version>
<configuration>
<archive>
<manifest>
<!-- Jar file entry point -->
<mainClass>org.postprocessor.dao.DaoMain</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
am not able to figure out where is the issue, my jar file doesn't have this config folder
DaoMain.java
package org.postprocessor.dao;
import java.io.File;
import org.postprocessor.util.FileZipper;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class DaoMain {
public static void main(String[] args) {
ApplicationContext ctx= new ClassPathXmlApplicationContext("classpath:/org/postprocessor/config/dataSupport.xml");
DaoImpl daoImpl=null;
FileZipper fileZipper=null;
try{
daoImpl= ctx.getBean("daoImpl",DaoImpl.class);
fileZipper= ctx.getBean("fileZipper",FileZipper.class);
daoImpl.startProcess();
fileZipper.zipFile(new File("").getAbsolutePath()+"/output");
}
catch(Exception e){
e.printStackTrace();
}
finally{
((ClassPathXmlApplicationContext) ctx).close();
}
}
}
How to solve this issue?
Looks like the main problem is at this line:
new ClassPathXmlApplicationContext("classpath:/org/postprocessor/config/dataSupport.xml");
You are trying to build context from classpath. Thus you have to locate your config file accessible from a classpath of your project.
You using Maven for building your project. Maven has defined project structure for code sources:
/src/main/java
and for resources:
/src/main/resorces
You can find more here: Introduction to the Standard Directory Layout
If you want to make your file accessible from classpath you have to put it exactly under - resources/ folder:
Now you main() will be, something like:
public static void main(String[] args) {
ApplicationContext ctx= new ClassPathXmlApplicationContext("classpath:config/dataSupport.xml");
Object dataSource = ctx.getBean("userRepo");
System.out.println(dataSource.getClass().getName());
// use your beans here
I created just demo bean. And here is output:
2017-03-20 15:22:40 INFO ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext#16f65612: startup date [Mon Mar 20 15:22:40 EET 2017]; root of context hierarchy
2017-03-20 15:22:40 INFO XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [config/dataSupport.xml]
demo.repository.UserRepository
BTW you can use try with resources for application context:
try(ClassPathXmlApplicationContext ctx =
new ClassPathXmlApplicationContext("classpath:config/dataSupport.xml")) {
// use your beans here
}
Additional resources:
using classpath: in spring
Java Spring - How to use classpath to specify a file location?
Your XML files are not well formed.
While I do not know if this is the issue, it may be the root cause of why your project is not taking the files correctly in the first place.
Your <beans> tag does not have a closing tag. Try putting </beans> at the end of the file.
Also, your pom.xml file has the same issue. The <project> is not closed. Try putting </project> at the end of the file.
I think the following should work:
ApplicationContext ctx= new ClassPathXmlApplicationContext("org/postprocessor/config/dataSupport.xml");
You don't need to specify "classpath" since you already use ClassPathXmlApplicationContext, and you have extra slash in the beginning.
move:
src/org/postprocessor/config/dataSupport.xml
to:
src/main/resources/org/postprocessor/config/dataSupport.xml
By default maven-compiler-plugin not includes non-java files. which left you with two options.
1. move your resource files (.properties, .xml etc) to "src/main/resources" (recomended.)
2. use maven resource plugin
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/path/where/you/want</outputDirectory>
<resources>
<resource>
<directory>${basedir}</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Related
We have file payment.jar that developed with Spring Framework 3.1.2 . We need to use it as a dependency on a new project that its version is Spring Framework 5.x .
Problem: When payment.jar used as a dependency, the payment.jar transitive dependencies add to project class-path so in cause conflicting Spring Framework 3 and Spring Framework 5.
I tried solutions:
big fat jar:
create-an-executable-jar-with-dependencies-using-maven
there is no success, the fat JAR, adds Spring Framework 3 to project. (what I am doing wrong!)
excluding payment Spring Framework 3.1.2 dependency in new project:
because of using spring-ibatis implementation in payment.jar it is not worked. Spring Framework new versions do not support ibatis.
Error:
Caused by: java.lang.ClassNotFoundException:
org.springframework.orm.ibatis.support.SqlMapClientDaoSupport
my requirement:
I need to use payment.jar (with Spring Framework 3.1.2) as a dependency on new project with Spring Framework 5.x without problem mentioned above.
If the Spring versions are as incompatible as it sounds as though they are, you're probably going to have to recompile either the jar or the project so that they're using the same version of Spring.
If that's impossible (e.g. if you don't have source for the jar), you might be able to wrap the payment jar up in a microservice so that it's running in a different process, and talk to it via XML-RPC or SOAP.
Your wish
I need to use payment.jar (with Spring Framework 3.1.2) as a
dependency on new project with Spring Framework 5.x without problem
mentioned above.
You cannot do it. Because the mismatching of version of dependencies. It is not backward compatible between many things, many version of iBatis, Spring Framework, payment.jar and other dependencies.
You must upgrade it manually.
The best option for this is to upgrade this manually.
Even if you will do this with Spring 3 jar, you will land with a lot of issues while compiling and running.
The ideal solution would be to update everything to Spring 5 or deploy payment.jar separately as a microservice as others mentioned. But this is not the core part of your question, maybe you have some unavoidable requirements. So as #tomer-shahar said the solution is to use maven shade plugin.
This kind of conflicts happen a lot when you use open source libraries sharing the same libraries but with different versions.
The maven shade plugin allows renaming/recolocating the packages selected avoiding conflicts within versions. The drawback is that some classes will be duplicated (so it is far from ideal). See the example below:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>spring321-payment-shaded</finalName>
<relocations>
<relocation>
<pattern>spring.package</pattern>
<shadedPattern>shaded.spring.package</shadedPattern>
</relocation>
</relocations>
<artifactSet>
<includes>
<include>*:*</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
And then add as dependency to the Spring 5 project this shaded library with all the renaming/rellocation done. I used this interesting article where all the details are fully described.
I suggest you to convert your jar in Spring 5 and MyBatis. I think it's the better solution in terms of mantenibility and compatibility. Migrate to iBatis to MyBatis does not a big problem, I think.
I had a working project that uses Spring 5 and My-Batis 3. I encountered some problem to configure it, but in the end, I solved everything. Just check the POM configuration and the Spring configuration.
POM configuration
In the following lines of code, you can read the project pom (I removed useless part of the file for your problem).
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>it.dummy</groupId>
<artifactId>dummy</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Dummy App</name>
<url>http://maven.apache.org</url>
<properties>
<java-source.version>1.8</java-source.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.skip.tests>true</maven.skip.tests>
<servlet-api.version>3.1.0</servlet-api.version>
<spring.version>5.0.7.RELEASE</spring.version>
<swagger.version>2.9.2</swagger.version>
<jackson.version>2.9.6</jackson.version>
<mybatis-spring>1.3.2</mybatis-spring>
<junit.version>4.12</junit.version>
<frontend-maven-plugin.version>1.4</frontend-maven-plugin.version>
<mapstruct.version>1.2.0.Final</mapstruct.version>
</properties>
<dependencies>
<!-- -->
<!-- https://mvnrepository.com/artifact/org.mapstruct/mapstruct -->
<!-- https://github.com/mapstruct/mapstruct -->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<!-- cucumber -->
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.14.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<!-- test -->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet-api.version}</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-rest-core -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-core</artifactId>
<version>3.0.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring Security Artifacts - START -->
<!-- http://mvnrepository.com/artifact/org.springframework.security/spring-security-web%20 -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- http://mvnrepository.com/artifact/org.springframework.security/spring-security-config%20 -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring Security Artifacts - END -->
<!-- Swagger - BEGIN -->
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<!-- Swagger - END -->
<!-- json -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>${jackson.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson.version}</version>
</dependency>
<!-- mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis-spring}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9</version>
</dependency>
</dependencies>
</project>
Just remember to check always the dependencies tree to avoid to have indesiderate Spring jars.
Spring configuration
I have different file for Spring configuration. I attach only the interesting one.
<?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:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:tx="http://www.springframework.org/schema/tx"
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://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource" destroy-method="close">
<property name="URL" value="jdbc:oracle:thin:#xxx:yyy:zzz" />
<property name="user" value="aaa"/>
<property name="password" value="bbb"/>
<property name="connectionCachingEnabled" value="true" />
</bean>
<bean id="transactionManagerNG" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="sqlSessionFactoryNG" class="org.mybatis.spring.SqlSessionFactoryBean" name="SqlSessionFactoryOrarioStandardDao">
<property name="dataSource" ref="dataSource" />
<!-- 1. Where is the xml for query's definitions -->
<property name="mapperLocations" value="classpath:com/dummy/persistence/dao/*.xml" />
<!-- 2. My-batis configuration -->
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
<!-- 3. My-batis type alias package -->
<property name="typeAliasesPackage" value="com.dummy.persistence.model" />
</bean>
<!-- 4. needed to parse Java DAO interfaces -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="it.insiel.sanita.farmacieng.persistence.dao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactoryNG"/>
</bean>
<tx:annotation-driven/>
</beans>
In the above Spring file you will find:
How I defined the location where put XML for SQL queries (comment 1)
How I use My-batis configuration (comment 2)
How I defined the type alias package (comment 3)
How I defined the DAO interfaces
Last but not least the My-batis configuration file mybatis-config.xml, that I put in the same folder of Spring configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<!-- http://mybatis.org/dtd/ -->
<configuration>
<settings>
<setting name="logImpl" value="LOG4J"/>
<setting name="cacheEnabled" value="true"/>
<setting name="defaultStatementTimeout" value="3000"/>
<setting name="mapUnderscoreToCamelCase" value="true"/>
<setting name="jdbcTypeForNull" value="NULL" />
</settings>
</configuration>
Though I have not done this with spring specifically, the general concept of what you are trying to accomplish is called shading.
https://softwareengineering.stackexchange.com/questions/297276/what-is-a-shaded-java-dependency
The reason the fat jar didn't work is because all jars were loaded to the classpath, and the wrong one will be chosen for at least on of the dependencies.
What you need to do is change the package name in both a dependency and the depending jar (in your case spring 3 and payment jar), so you basically end up with two pairs of dependencies that don't overlap.
This is relatively simple to do in maven and similar tools. See the link for more details.
I have created a runnable jar using maven assembly plugin:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.loaders.FundLoader</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
I have some Spring dependencies packaged into the jar.
When I run the program using intellIj the program runs perfectly fine.
However when I run the program from the command line using: java -jar myjar.jar
I got the following exception:
Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefiniti
onStoreException: Line 6 in XML document from class path resource [spring/loader-context.xml] is invalid; nested exception is org.xml.sax.SAXParseExceptio
n; lineNumber: 6; columnNumber: 120; cvc-elt.1: Cannot find the declaration of e
lement 'beans'.
Attached my config file: loader-context.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"
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.xsd">
<context:annotation-config />
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:hibernate.properties</value>
</list>
</property>
<property name="ignoreResourceNotFound" value="false"/>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${hibernate.driver.class.name}" />
<property name="url" value="${hibernate.jdbc.url}" />
<property name="username" value="${hibernate.username}" />
<property name="password" value="${hibernate.password}" />
<property name="defaultAutoCommit" value="false" />
</bean>
</beans>
And then the content of my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.operations</groupId>
<artifactId>parent</artifactId>
<version>3.0.2-SNAPSHOT</version>
</parent>
<artifactId>loader</artifactId>
<name>[FOR] loader</name>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.loaders.FundLoader</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.4.0</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
<scope>runtime</scope>
</dependency>
</dependencies>
Could someone please help me out ?
Thank you
Spring applications cannot be simly packaged as a fat JAR with the maven-assembly-plugin, for each Spring module JAR has its schemas located in a file that is always at the same location (META-INF/spring.schemas).
When you flatten all your dependencies in one final JAR, you will obviously only has one of these spring.schemas files in your resulting JAR, hence your issue.
I would suggest to either use Spring Boot for developing your application, as it includes a plugin that deals nicely with Spring JARs.
Or you can also use onejar-maven-plugin, which also packages the fat JAR in a specific way that avoids having this issue.
Other solutions also exists, such as the maven-shade-plugin and its AppendingTransformer
You can even provide merged versions of the problematic files by yourself, as project resources, and then excluding the originals from being assembled.
Unable to Start the deployed war file.
I got the following error at the terminal
[ERROR] 17:23:17 ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in resource loaded from byte array: Cannot resolve reference to bean 'blPersistenceUnitManager' while setting bean property 'persistenceUnitManager';
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blPersistenceUnitManager': Injection of resource dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blMergedDataSources' defined in resource loaded from byte array: Cannot resolve reference to bean 'webDS' while setting bean property 'sourceMap' with key [TypedStringValue: value [jdbc/web], target type [null]];
The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
Context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<ResourceLink global="jdbc/web" name="jdbc/web" type="javax.sql.DataSource"/>
</Context>
Server.xml
<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
<Listener className="org.apache.catalina.core.JasperListener"/>
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<GlobalNamingResources>
<Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
<Resource auth="Container"
driverClassName="com.mysql.jdbc.Driver"
initialSize="5"
maxActive="120"
maxIdle="5"
maxWait="5000"
name="jdbc/web"
username="root"
password="admin123"
poolPreparedStatements="true"
type="javax.sql.DataSource"
url="jdbc:mysql://localhost:3306/broadleaf"
validationQuery="select 1"/>
</GlobalNamingResources>
<Service name="Catalina">
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
<Engine defaultHost="localhost" name="Catalina">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
</Host>
</Engine>
</Service>
</Server>
Thank you for your valuable advice. I have edited the post with server.xml and context.xml.
I am following broadleafcommerce's tutorial [http://www.broadleafcommerce.com/docs/core/current/getting-started].
In order to configure Switching to MySql I have made changes as in this link [http://www.broadleafcommerce.com/docs/core/current/tutorials/getting-started-tutorials/switch-to-mysql-tutorial]
applicationContext-servlet.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:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<context:component-scan base-package="org.broadleafcommerce.common.web"/>
<context:component-scan base-package="org.broadleafcommerce.profile.web.controller"/>
<context:component-scan base-package="org.broadleafcommerce.profile.web.core.service.login"/>
<context:component-scan base-package="com.heatclinic.sample" />
<!-- Turn on AOP annotations (required by Broadleaf) -->
<aop:config/>
<bean class="org.broadleafcommerce.core.web.catalog.ProductHandlerMapping">
<property name="order" value="2"/>
</bean>
<bean class="org.broadleafcommerce.cms.web.PageHandlerMapping">
<property name="order" value="3"/>
</bean>
<bean class="org.broadleafcommerce.core.web.catalog.CategoryHandlerMapping">
<property name="order" value="4"/>
</bean>
<context:component-scan base-package="com.heatclinic.controller" />
<mvc:annotation-driven/>
<mvc:interceptors>
<bean id="webContentInterceptor" class="org.broadleafcommerce.core.web.interceptor.NonResourceWebContentInterceptor">
<property name="cacheSeconds" value="0"/>
<property name="useExpiresHeader" value="true"/>
<property name="useCacheControlHeader" value="true"/>
<property name="useCacheControlNoStore" value="true"/>
</bean>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="blLocaleCode"/>
</bean>
</mvc:interceptors>
<bean id="localeResolver" class="org.broadleafcommerce.common.web.BroadleafCookieLocaleResolver" />
<mvc:resources order="-10" location="/img/, classpath:/common_style/img/" mapping="/img/**" />
<mvc:resources order="-10" location="/fonts/, classpath:/common_style/fonts/" mapping="/fonts/**" />
<mvc:resources order="-10" location="WEB-INF/favicon.ico" mapping="/favicon.ico" />
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="order" value="-10" />
<property name="mappings">
<props>
<prop key="/js/**">blJsResources</prop>
<prop key="/css/**">blCssResources</prop>
</props>
</property>
</bean>
<!-- Set up the view resolver to be used by Spring -->
<bean class="org.broadleafcommerce.common.web.BroadleafThymeleafViewResolver">
<property name="templateEngine" ref="blWebTemplateEngine" />
<property name="order" value="1" />
<property name="cache" value="${thymeleaf.view.resolver.cache}" />
<property name="fullPageLayout" value="layout/fullPageLayout" />
<property name="characterEncoding" value="UTF-8" />
<property name="layoutMap">
<map>
<entry key="account/" value="layout/accountLayout" />
<entry key="catalog/" value="NONE" />
<entry key="checkout/" value="layout/checkoutLayout" />
<entry key="checkout/confirmation" value="layout/fullPageNoNavLayout" />
<entry key="layout/" value="NONE" />
<entry key="content/NONE" value="NONE" />
</map>
</property>
</bean>
<bean id="blShippingInfoFormValidator" class="org.broadleafcommerce.core.web.checkout.validator.USShippingInfoFormValidator" />
</beans>
Even though I have added hibernate-3.2.7.ga.jar file to the lib directory, I get this exception -ClassLoadingException:Unable to load class [org.hibernate.dialect.MySQL5InnoDBDialect] .
[ERROR] 11:09:39 ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blEntityManagerFactorySecureInfo' defined in resource loaded from byte array: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: blSecurePU] Unable to build EntityManagerFactory
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: blSecurePU] Unable to build EntityManagerFactory ....
Caused by: org.hibernate.HibernateException: Dialect class not found: org.hibernate.dialect.MySQL5InnoDBDialect ...
Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class [org.hibernate.dialect.MySQL5InnoDBDialect ] ....
Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.dialect.MySQL5InnoDBDialect ...
But the jar file do have the class.
3576 Wed Jun 03 16:19:06 PDT 2009 org/hibernate/dialect/MckoiDialect.class
5326 Wed Jun 03 16:19:06 PDT 2009 org/hibernate/dialect/MimerSQLDialect.class
595 Wed Jun 03 16:19:06 PDT 2009 org/hibernate/dialect/MySQL5Dialect.class
648 Wed Jun 03 16:19:06 PDT 2009 org/hibernate/dialect/MySQL5InnoDBDialect.class
9682 Wed Jun 03 16:19:06 PDT 2009 org/hibernate/dialect/MySQLDialect.class
642 Wed Jun 03 16:19:06 PDT 2009 org/hibernate/dialect/MySQLInnoDBDialect.class
544 Wed Jun 03 16:19:06 PDT 2009 org/hibernate/dialect/MySQLMyISAMDialect.class
And also I have not mentioned anything about the hibernate dependencies in the pom.xml file.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.heatclinic</groupId>
<artifactId>ecommerce-website</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>ecommerce</name>
<url>http://www.blc-archetype.com</url>
<properties>
<blc.version>3.1.8-GA</blc.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<description>My Company's eCommerce Website</description>
<repositories>
<repository>
<id>public snapshots</id>
<name>public snapshots</name>
<url>http://nexus.broadleafcommerce.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.zeroturnaround</groupId>
<artifactId>jrebel-maven-plugin</artifactId>
<versionRange>[1.0,)</versionRange>
<goals>
<goal>generate</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<versionRange>[1.3,)</versionRange>
<goals>
<goal>run</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
build-helper-maven-plugin
</artifactId>
<versionRange>
[1.7,)
</versionRange>
<goals>
<goal>
timestamp-property
</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
keytool-maven-plugin
</artifactId>
<versionRange>
[1.5,)
</versionRange>
<goals>
<goal>clean</goal>
<goal>generateKeyPair</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.zeroturnaround</groupId>
<artifactId>jrebel-maven-plugin</artifactId>
<version>1.1.3</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>target</directory>
<includes>
<include>**/*</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>default-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
<file>
<exists>${java.home}/../lib/tools.jar</exists>
</file>
</activation>
<properties>
<toolsjar>${java.home}/../lib/tools.jar</toolsjar>
</properties>
</profile>
<profile>
<id>mac-profile</id>
<activation>
<activeByDefault>false</activeByDefault>
<file>
<exists>${java.home}/../Classes/classes.jar</exists>
</file>
</activation>
<properties>
<toolsjar>${java.home}/../Classes/classes.jar</toolsjar>
</properties>
</profile>
</profiles>
<dependencyManagement>
<dependencies>
<!-- Activated by the profiles above for the paths to tools.jar-->
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>[1.6,)</version>
<scope>system</scope>
<systemPath>${toolsjar}</systemPath>
</dependency>
<dependency>
<groupId>com.heatclinic</groupId>
<artifactId>core</artifactId>
<version>1.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<!--Broadleaf libraries -->
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>broadleaf-common</artifactId>
<version>${blc.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>broadleaf-profile</artifactId>
<version>${blc.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>broadleaf-profile-web</artifactId>
<version>${blc.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>broadleaf-framework</artifactId>
<version>${blc.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>broadleaf-framework-web</artifactId>
<version>${blc.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>broadleaf-admin-module</artifactId>
<version>${blc.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>broadleaf-contentmanagement-module</artifactId>
<version>${blc.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>broadleaf-open-admin-platform</artifactId>
<version>${blc.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>integration</artifactId>
<version>${blc.version}</version>
<type>jar</type>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<!-- Other dependencies -->
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.3.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.9</version>
<type>jar</type>
<classifier>jdk15</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
<version>7.0.30</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>admin</module>
<module>core</module>
<module>site</module>
</modules>
</project>
I don't find the file named applicationContext-servlet-cms-contentClient.xml in the project.
I wish you'd posted your xml for your spring configuration so I could see if there were any more issues but at the very least you'll need to define all your jndi names in tomcat - in server.xml as a <resource /> in <globalnames /> and context.xml as <resourcelink /> in the <context /> tag. Server.xml will look something like this (you will need to select proper setting for the type of db your using):
<GlobalNamingResources>
<Resource auth="Container"
driverClassName="com.mysql.jdbc.Driver"
initialSize="5"
maxActive="120"
maxIdle="5"
maxWait="5000"
name="jdbc/web"
username="user"
password="password"
poolPreparedStatements="true"
type="javax.sql.DataSource"
url="jdbc:mysql://localhost:3306/dbname"
validationQuery="select 1"/>
</GlobalNamingResources>
Although don't delete resources already defined. And this in context.xml:
<context>
<ResourceLink global="jdbc/web" name="jdbc/web" type="javax.sql.DataSource"/>
</context>
I don't want to get dunned for including a link but if you search "tomcat jndi datasource how to" I think you'll find at least one thorough example of what's needed. You'll also need to include the jar containing your driver (com.mysql.jdbc.Driver in this example) in tomcat/lib.
Finally I got answer to my question. Adding hibernate dependencies to my pom.xml did the trick. Also don't forget to add hibernate jar(hibernate-3.2.7.ga.jar) file to lib directory.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.7.ga</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
I think adding the above code resolved the ClassLoadingException:Unable to load class [org.hibernate.dialect.MySQL5InnoDBDialect] which was mentioned in my post.
Answers from Bill fixed JNDI naming error.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I started spring mvc project and tried to use JPA there. I have class User and BasePersistable with accessors generated by #RooJavaBean.
import javax.persistence.GeneratedValue;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;
import org.springframework.data.annotation.Id;
import org.springframework.data.domain.Persistable;
import org.springframework.roo.addon.javabean.RooJavaBean;
#RooJavaBean
#MappedSuperclass
public abstract class BasePersistable implements Persistable<Long> {
private static final long serialVersionUID = -3281161320810540373L;
#Id
#GeneratedValue
private Long id;
#Version
private Integer version;
#Override
public boolean isNew() {
return getId() == null;
}
}
and
#Entity
#RooJavaBean
public class User extends BasePersistable {
private static final long serialVersionUID = -1999311284585286126L;
private String username;
private String passwrd;
private String firstname;
private String lastname;
private String email;
#Temporal(TemporalType.TIMESTAMP)
private Calendar signupDate;
private Sex sex;
private String comment;
}
Roo definitely generate getters and setters.
I can access getId() method in code:
User user = new User();
user.getId();
But I got this error:
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.test:mvc1:war:1.0.0-BUILD-SNAPSHOT
[WARNING] 'build.plugins.plugin.(groupId:artifactId)' must be unique but found duplicate declaration of plugin org.codehaus.mojo:aspectj-maven-plugin # line 284, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mvc1 1.0.0-BUILD-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) # mvc1 ---
[INFO] Deleting /home/zzz/ws_java/mvc1/target
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) # mvc1 ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # mvc1 ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 6 source files to /home/zzz/ws_java/mvc1/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/zzz/ws_java/mvc1/src/main/java/com/test/mvc1/domain/User.java:[13,7] error: User is not abstract and does not override abstract method getId() in Persistable
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.831s
[INFO] Finished at: Sat Aug 11 09:56:58 NOVT 2012
[INFO] Final Memory: 16M/86M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project mvc1: Compilation failure
[ERROR] /home/zzz/ws_java/mvc1/src/main/java/com/test/mvc1/domain/User.java:[13,7] error: User is not abstract and does not override abstract method getId() in Persistable
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
It seems that there are some problems with AspectJ I think. Can anyone help?
UPD
Here is BasePersistable_Roo_JavaBean.aj
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
// You may push code into the target .java compilation unit if you wish to edit any member(s).
package com.test.mvc1.domain;
import com.test.mvc1.domain.BasePersistable;
privileged aspect BasePersistable_Roo_JavaBean {
public Long BasePersistable.getId() {
return this.id;
}
public void BasePersistable.setId(Long id) {
this.id = id;
}
public Integer BasePersistable.getVersion() {
return this.version;
}
public void BasePersistable.setVersion(Integer version) {
this.version = version;
}
}
By the way if to add stub method getId() to User class:
public Long getId() {
return 1L;
}
UPD 2
I cant even imagine what is wrong with the project. I add new dependency in pom file and maven does not download it. Here is my pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>mvc1</artifactId>
<name>mvc1</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
<java-version>1.7</java-version>
<spring.version>3.1.0.RELEASE</spring.version>
<aspectj.version>1.6.12</aspectj.version>
<org.slf4j-version>1.5.10</org.slf4j-version>
<roo.version>1.2.1.RELEASE</roo.version>
<data-jpa.version>1.1.0.M1</data-jpa.version>
<tiles.version>2.2.2</tiles.version>
<hibernate-jpa-api.version>1.0.1.Final</hibernate-jpa-api.version>
<hibernate-entity-manager.version>4.1.0.Final</hibernate-entity-manager.version>
<aspectj-plugin.version>1.2</aspectj-plugin.version>
<eclipse-plugin.version>2.7</eclipse-plugin.version>
<compiler-plugin.version>2.3.2</compiler-plugin.version>
<!-- database properties start -->
<database.url>jdbc:mysql://localhost:3306/mvctest</database.url>
<database.username>root</database.username>
<database.password />
<database.driverClassName>com.mysql.jdbc.Driver</database.driverClassName>
<database.type>MYSQL</database.type>
<!-- database properties end -->
</properties>
<repositories>
<repository>
<id>spring-maven-release</id>
<name>Spring Maven Release Repository</name>
<url>http://maven.springframework.org/release</url>
</repository>
<repository>
<id>spring-maven-milestone</id>
<name>Spring Maven Milestone Repository</name>
<url>http://maven.springframework.org/milestone</url>
</repository>
<repository>
<id>spring-roo-repository</id>
<name>Spring Roo Repository</name>
<url>http://spring-roo-repository.springsource.org/release</url>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>${data-jpa.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<!-- Hibernate/Jpa -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate-entity-manager.version}</version>
</dependency>
<!-- Database -->
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.18</version>
</dependency>
<!-- Roo -->
<dependency>
<groupId>org.springframework.roo</groupId>
<artifactId>org.springframework.roo.annotations</artifactId>
<version>${roo.version}</version>
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>
<!-- #Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>${tiles.version}</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/*.properties</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<!-- version is used because of Roo 1.2.1.RELEASE requirement -->
<!-- remove it when fixed -->
<version>${eclipse-plugin.version}</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
<wtpversion>2.0</wtpversion>
<additionalBuildcommands>
<buildCommand>
<name>org.eclipse.ajdt.core.ajbuilder</name>
<arguments>
<aspectPath>org.springframework.aspects</aspectPath>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
</buildCommand>
</additionalBuildcommands>
<additionalProjectnatures>
<projectnature>org.eclipse.ajdt.ui.ajnature</projectnature>
<projectnature>com.springsource.sts.roo.core.nature</projectnature>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>${aspectj-plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<outxml>true</outxml>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.test.int1.Main</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.4.v20120524</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<junitArtifactName>org.junit:com.springsource.org.junit</junitArtifactName>
<excludes>
<exclude>**/*_Roo_*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Here is my servlet-context:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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: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.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<!-- ========================= GENERAL DEFINITIONS ========================= -->
<mvc:annotation-driven />
<mvc:resources location="/resources/" mapping="/resources/**"/>
<context:property-placeholder location="classpath*:META-INF/spring/*.properties" />
<context:component-scan base-package="com.test.mvc1.web">
<context:exclude-filter expression=".*_Roo_.*" type="regex"/>
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
</context:component-scan>
<jpa:repositories base-package="com.test.mvc1.repository" />
<!-- ========================= VIEW DEFINITIONS ========================= -->
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver" id="tilesViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
</bean>
<!-- ========================= TILES DEFINITIONS ========================= -->
<bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer" id="tilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/defs/tiles.xml</value>
</list>
</property>
</bean>
<!-- ========================= Persistence configuration ========================= -->
<jpa:repositories base-package="com.test.mvc1.repository" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${database.driverClassName}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.username}" />
<property name="password" value="${database.password}" />
<property name="testWhileIdle" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<property name="validationQuery" value="SELECT NOW()" />
</bean>
<bean id="entityManagerFactory" depends-on="liquibase" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.test.mvc1.domain, ${database.packagesToScan}" />
<property name="jpaProperties">
<props>
<prop key="hibernate.ejb.naming_strategy">${database.namingStrategy}</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.show_sql">${database.showsql}</prop>
<prop key="hibernate.hbm2ddl.auto">${database.hbm2ddl}</prop>
<prop key="hibernate.connection.charSet">UTF-8</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
</props>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="${database.type}" />
<property name="showSql" value="${database.showsql}" />
<property name="generateDdl" value="false" />
</bean>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager" />
<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase">
<property name="changeLog" value="classpath:META-INF/db/changelog.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
Here is errors:
2012-08-12 10:42:24.250:WARN:/:unavailable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build EntityManagerFactory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
Caused by:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build EntityManagerFactory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
Caused by:
javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
Caused by:
org.hibernate.AnnotationException: No identifier specified for entity: com.test.mvc1.domain.User
at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:276)
2012-08-12 10:42:24.525:INFO:oejs.AbstractConnector:Started SelectChannelConnector#0.0.0.0:8080
[INFO] Started Jetty Server
I need help!
I suppose that the matter is versions conflicts in some dependencies or plugins.
EDIT: Updating the answer as pre modified question...
org.hibernate.AnnotationException: No identifier specified for entity: com.malykhinvi.mvc1.domain.User
So here the error says that your entity com.malykhinvi.mvc1.domain.User doesn't have an #Id annotation to depict the primary key.
Can you try placing for BasePersistable
#Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
I'm trying to create integration tests using hsqldb in an in memory mode. At the moment, I have to start the hsqldb server from the command line before running the unit tests. I would like to be able to control the hsqldb server from my integration tests. I can't seem to get this to all work out though from code.
Update:
This appears to work along with having a hibernate.cfg.xml file in the classpath:
org.hsqldb.Server.main(new String[]{});
and in my hibernate.cfg.xml file:
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:mem:ww</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="hbm2ddl.auto">update</property>
Update
It appears that this is only a problem when running the unit tests from within Eclipse using jUnit and the built in test runner. If I run
mvn test
they are executed correctly and there is no exception. Am I missing something as far as a dependency goes? I have generated the eclipse project using
mvn eclipse:eclipse
and my pom is:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproject</groupId>
<artifactId>myproject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>myproject</name>
<dependencies>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.3.2.GA</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.1.0.4.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.8.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.4.0.GA</version>
</dependency>
<!-- Test Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-servlet-tester</artifactId>
<version>6.1.24</version>
<scope>test</scope>
</dependency>
<!-- Provided -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>servlet-api</artifactId>
<version>6.0.26</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>jsp-api</artifactId>
<version>6.0.26</version>
</dependency>
</dependencies>
<build>
<finalName>ww_main</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Update
Ok, well not sure what exactly was going wrong here, but I seemed to have fixed it. I deleted all the files that HSQLDB created, as well as all of the created files in my Maven target folder, did a clean, recreated my eclipse .project using maven and refreshed the project in eclipse. I think I may have had something left over from a previous configuration that was throwing it off.
Thanks for everyone's help!
I use the following configuration (directly inspired by the Hibernate tutorial) without any problem:
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
<property name="hibernate.connection.url" value="jdbc:hsqldb:mem:foobar"/>
<property name="hibernate.connection.username" value="sa"/>
<property name="hibernate.connection.password" value=""/>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hibernate.hbm2ddl.auto" value="update"/>
<mapping resource="..."/>
</session-factory>
</hibernate-configuration>
When using an in-memory HSQLDB, there is no need to start anything explicitly. Just use the mem: protocol and the in-memory database will get started from JDBC.
See also
Unit-Testing Hibernate With HSQLDB
Try appending this to the jdbc url:
;ifexists=true;shutdown=true;
In your shutdown method just do
Statement st = conn.createStatement();
st.execute("SHUTDOWN");
conn.close();
What about starting server through Runtime.getRuntime().exec("shell command here")? You have to do it only once for all tests, so it won't add too big lag.
Update
Ok, looks like you've solved it yourself :)
Update 2
To execute some code once before (or after) unit tests, you can
static class TestWrapper extends TestSetup {
TestWrapper(TestSuite suite) {
super(suite);
}
protected void setUp() throws Exception {
// start db
}
protected void tearDown() throws Exception {
// kill db
}
}
Then, just wrap your test set in it: new TestWrapper(suite)
Maybe this might help to start HSQL in server mode in a Unit test, but in the same JVM.
Sample code runs org.hsqldb.server.WebServer (i.e. port 80) but you may use org.hsqldb.server.Server. You may call setPort on either to override default port.
https://stackoverflow.com/a/37784679/15789
check my hsqldb maven plugin :
https://github.com/avianey/hsqldb-maven-plugin
You can just start/stop it like jetty-maven-plugin or tomee-maven-plugin for your tests :
<plugin>
<!-- current version -->
<groupId>fr.avianey.mojo</groupId>
<artifactId>hsqldb-maven-plugin</artifactId>
<version>1.0.0</version>
<!--
default value for in memory jdbc:hsqldb:hsql://localhost/xdb
override only values you want to change
-->
<configuration>
<driver>org.hsqldb.jdbcDriver</driver>
<path>mem:test</path>
<address>localhost</address>
<name>xdb</name>
<username>sa</username>
<password></password>
<validationQuery>SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS</validationQuery>
</configuration>
<!-- call start and stop -->
<executions>
<execution>
<id>start-hsqldb</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-hsqldb</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>