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.

Paushchyk Julia
  • 516
  • 3
  • 8
  • 24
  • Have a look at http://stackoverflow.com/questions/11559846/how-to-list-files-inside-a-folder-with-sql-server. It might help you. – Litisqe Kumar Jul 01 '15 at 11:21

1 Answers1

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! :)

Lucas Saldanha
  • 891
  • 7
  • 13