Is there a way to save java variable / object in application context without xml or properties file

I want to save a specific variable (String or Object) in the application context in the spring boot application. But I do not want to use the xml or properties file to store it.

There will be a function that will store data in the context of the application. I should be able to retrieve it, modify, delete or add additional data.

Basically I want to store data in the context of the application after its initialization.

+4
source share
2 answers

, .
, , .

, Spring Beans .
, .

, , singleton , .
.

+1

@Configuration. beans @Bean, beans?

@Configuration
public class ConfigurationClass {

@Bean("myString")
public String getString() {     
    return "Hello World";
}

- AnnotationConfigWebApplicationContext.getBean("myString"), bean.

concurrency ( davidxxx). SimpleThreadScope. , ( google it).

, , a @Scope("request") . bean @Scope("request") , , , .

+1

Source: https://habr.com/ru/post/1675460/


All Articles