4

I am running a spring boot application with the following structure

Main Application com/my/application/app/boot/AppStarter.java depends on Lib Application Lib Application META-INF/package/persistence.xml com/my/application/data/Entity1.java 

Where Entity 1 is a persistence object using @Entity and @Table annotations

AppStarter is as follows:

@ComponentScan({ "com.my.application.sampleScan1", "com.my.application.sampleScan2"}) @EntityScan(basePackages={"com.my.application.data"}) @EnableAutoConfiguration @Configuration @PropertySources({ @PropertySource(value = "classpath:application.properties", ignoreResourceNotFound = true), @PropertySource(value = "classpath:test.properties", ignoreResourceNotFound = true) }) @ImportResource({ "classpath:my/application/fake/fakeContext.xml"}) public class FakeAppBooter { public static void main(String args[]) { SpringApplication.run(FakeAppBooter.class, args); } } 

When I package this using the spring boot application as a jar, The Lib Application is within the /lib/LibApplication.jar , however when it tries to access the Entity Entity1, I get an: org.hibernate.MappingException: Unknown entity: com.my.application.data.Entity1

When this is executed from within eclipse, this works fine, it only breaks when i run the spring-boot-plugin generated jar.

3
  • Same boat. Got any paddles? Commented Sep 16, 2016 at 22:55
  • This has been ages and i do not remember what the actual issue was. What i do remember is that Spring boot annotation and xml configuration did not work well together. If you can try to switch to annotation-only or xml-only configuration it might help. Commented Sep 17, 2016 at 12:26
  • 1
    I was missing @EntityScan Commented Oct 7, 2016 at 17:18

2 Answers 2

1

Instead of using the annotations individually, the best practice is just to use

@SpringBootApplication 

To annotate your class, and let Spring Boot do the rest.

Sign up to request clarification or add additional context in comments.

Comments

1

You need component scan for all your packages and entity scan for all your entities

com.uganda.** and com.uganda.**.entity

all should be included in your boot application class as follows

 @SpringBootApplication @ComponentScan({ "com.uganda"}) @EntityScan(basePackages= {"com.uganda"}) public class MyBootpApplication { 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.