hibernate - Fetching global values from database on application startup in Spring boot -


i'm writing spring boot / jpa application. have values needs visible entire application , these values located in database. should fetch these values? should fetch them in class containing @springbootapplication?

and how make visible application? read spring, can use @bean class hold global variables. have map @entity class bean class , autowire bean class ever want? i'm new spring / jpa, apologize if question basic.

thanks.

make bean instantiated applicationcontext, , use init-method run code after it's instantiated.

a off top of head solution:

in applicationcontext.xml:

<bean class="com.example.dbconfigloader" init-method="init">

a class load config entity @ startup:

public class dbconfigloader {      @autowired     private dbconfigrepository repository;      private dbconfig dbconfig;      public void init(){         dbconfig = repository.findone(1l);     }      public dbconfig getdbconfig() {         return dbconfig;     } } 

a class representing config:

@entity public class dbconfig {      @id     private long id;      private string somesetting;      public string getsomesetting() {         return somesetting;     } } 

a spring data repository easy database access:

public interface dbconfigrepository extends jparepository<dbconfig, long> { } 

Popular posts from this blog

html/hta mutiple file in audio player -