This project shows how to use Spring Boot with EclipseLink as a JPA provider, configure the project for to package WAR-file, and develop in Eclipse IDE.
- Maven
- In
pom.xml
transitive dependencyhibernate-entitymanager
excluded from theorg.springframework.boot
eclipselink
dependency addedmaven-surefire-plugin
andspring-boot-maven-plugin
are configured to usespring-instrument
for dynamic weaving
- In
- Spring Boot
JpaConfiguration.java
sets upEclipseLinkJpaVendorAdapter
- Best weaving mode is selected:
dynamic
ifspring-instrument
agent is present, andstatic
mode otherwise (even if classes are not weaved, the application will still run infalse
mode)
- Maven
- Packaging ist set to
war
spring-boot-starter-tomcat
set toprovided
scopestaticweave-maven-plugin
is added to statically weave persistence classes for war-file which can then run without any javaagents.
- Packaging ist set to
- Spring Boot
- Class
SampleDataJpaApplication
extendsSpringBootServletInitializer
- Class
- Maven
spring-boot-maven-plugin
: optionaddResources
is set tofalse
to not to conflict with Eclipse behaviour.
To run the application, JUnits or Tomcat inside the IDE with dynamic weaving, add following arguments to JVM:
-noverify
-javaagent:${env_var:USERPROFILE}\.m2\repository\org\springframework\spring-instrument\4.1.6.RELEASE\spring-instrument-4.1.6.RELEASE.jar
-javaagent:${env_var:USERPROFILE}\.m2\repository\org\springframework\springloaded\1.2.3.RELEASE\springloaded-1.2.3.RELEASE.jar
Notes:
- The order of the agents is important!
- Remove line breaks!
- Update versions according to your pom
- Agent
springloaded
is optional - To download the required jars to your local Maven repository, just run
mvn spring-boot:run
once
This setup can run all possible ways:
- Deploy on Tomcat inside Eclipse
- Or execute
SampleDataJpaApplication
insede Eclipse - Or run
mvn spring-boot:run
- Or run
mvn package
and then:- either deploy
target\projectname.war
- or run
java -jar target\projectname.war
- either deploy
Slf4jSessionLogger
included that forwards EclipseLink logging to Slf4J. Read the javadoc andapplication.yml
for more information.logback-custom.xml
can be activated by uncommenting environment variables in /webapp/META-INF/context.xml (works only when running as deployment on Tomcat)