Create your copy with maven archetype generate:
mvn archetype:generate -DarchetypeGroupId=com.philippkoelmel -DarchetypeArtifactId=spring-rest-webapp-archetype -DarchetypeVersion=0.0.1-SNAPSHOT -DarchetypeRepository=https://github.com/Hechtenheld/maven-repo/raw/master/snapshots
In order to setup your own project, you need to modify these files.
The skeleton assumes that you use JNDI in production. There is a reference to a jdbc/production
in this file. Modify it as you wish.
<resource-ref>
<description>Production Database</description>
<res-ref-name>jdbc/production</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
This file defines the reference to the production database.
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/production" />
</bean>
Configures a JDBC datasource for testing that points to a HSQLDB and a database called skeleton
. Find more options in test-datasource.xml
. If you use another DBMS, please also change the dependencies to HSQL in the pom.xml
.
driverClass=org.hsqldb.jdbcDriver
jdbcUrl=jdbc:hsqldb:mem:test
user=sa
password=
databasePlatform=org.hibernate.dialect.HSQLDialect
All context files are imported by this one. Except the datasource definition which is imported by the dispatcher-servlet.xml
if run in a web container or test-context.xml
if a test is executed. In this file just change the base-package
attribute to your package name.
<context:component-scan base-package="your.package.skeleton" />
The entityManagerFactory
is defined in this file. You need to change the property persistenceUnitName
.
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="skeletonPU" />
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter">
</property>
</bean>
Add you entity classes here. Maybe you also want to rename the PU by changing the attribute name
of the persistence-unit
tag.
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="skeletonPU">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.philippkoelmel.skeleton.skull.Skull</class>
</persistence-unit>
</persistence>
If you are not using MySQL for your production database, change databasePlatform
.
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="true" />
<property name="showSql" value="true" />
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" />
</bean>
You can do two things here:
-
If you change the DBMS for testing, be sure to change the HSQL dependency also
-
You can change the version via the properties defined
org.hsqldb hsqldb-j5 ${org.hsqldb.version} ... 3.0.5.RELEASE 3.5.4-Final 0.9.1 4.8.2 ...
- Eclipse Helios for Java EE Developer Via Help/Eclipse Marketplace:
- SpringSource Tool Suite
- Spring IDE
- Maven Integration for Eclipse