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.xmltransitive dependencyhibernate-entitymanagerexcluded from theorg.springframework.boot eclipselinkdependency addedmaven-surefire-pluginandspring-boot-maven-pluginare configured to usespring-instrumentfor dynamic weaving
- In
- Spring Boot
JpaConfiguration.javasets upEclipseLinkJpaVendorAdapter- Best weaving mode is selected:
dynamicifspring-instrumentagent is present, andstaticmode otherwise (even if classes are not weaved, the application will still run infalsemode)
- Maven
- Packaging ist set to
war spring-boot-starter-tomcatset toprovidedscopestaticweave-maven-pluginis added to statically weave persistence classes for war-file which can then run without any javaagents.
- Packaging ist set to
- Spring Boot
- Class
SampleDataJpaApplicationextendsSpringBootServletInitializer
- Class
- Maven
spring-boot-maven-plugin: optionaddResourcesis set tofalseto 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
springloadedis optional - To download the required jars to your local Maven repository, just run
mvn spring-boot:runonce
This setup can run all possible ways:
- Deploy on Tomcat inside Eclipse
- Or execute
SampleDataJpaApplicationinsede Eclipse - Or run
mvn spring-boot:run - Or run
mvn packageand then:- either deploy
target\projectname.war - or run
java -jar target\projectname.war
- either deploy
Slf4jSessionLoggerincluded that forwards EclipseLink logging to Slf4J. Read the javadoc andapplication.ymlfor more information.logback-custom.xmlcan be activated by uncommenting environment variables in /webapp/META-INF/context.xml (works only when running as deployment on Tomcat)