0

I need to scan my SQL files, SQL-files for create tables in db. Now I have:

import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;

@Configuration
@EntityScan({"model"}) //in folder model put SQL-files
@ComponentScan(basePackageClasses = { MyApiServiceImpl.class})
@Import({DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public class TestConfig {
...
}

But this cannot to get SQL-files from model folder, because in model folder must to put entity classes, but I want SQL-files in model folder.

1

1 Answer 1

1

I don't believe that @EntityScan works for scanning sql files (http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/orm/jpa/EntityScan.html). Actually it scan classes with the @Entity annotation. If you want your files to be automatically in your application's classpath you should put them in the src/main/resources folder (if you are using maven/gradle).

If you want Spring to execute the sql to create your database schema, you should use a schema.sql file in your classpath (http://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html).

I hope it helps! :)

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.