Search code examples
spring-boottextpositionwar

where to put text file in war packing spring boot


I have a spring boot web project, and I have some kind of DB(data-base) in few text files(I don't want to use MongoDB or MySQL), and my whole project works, but once I pack it in war it says error 500 and that it cant find these text files that have crucial information.

Where do I need to put these text files?


Solution

  • Considering you are using Spring Boot, add this dependency and then load it to your boot app::

    <dependency>
        <groupId>com.github.ulisesbocchio</groupId>
        <artifactId>spring-boot-jar-resources</artifactId>
        <version>1.3</version>
    </dependency>
    
    
    
    public static void main(String[] args) {
            StandardEnvironment environment = new StandardEnvironment();
            new SpringApplicationBuilder()
                .sources(SpringBootJarResourcesDemoApplication.class)
                .environment(environment)
                .resourceLoader(new JarResourceLoader(environment, "resources.extract.dir"))
                .build()
                .run(args);
        }