Initialization and destruction

Report a typo

Select all ways to invoke custom initialization and destruction by the Spring Container for the following template.

Java
@Configuration
class Config {

    @Bean
    public MovieStorage storage() {
        return new MovieStorage();
    }
}

class MovieStorage {
    private final List<String> movies = Collections.synchronizedList(new ArrayList<>());

    public void init() {
        // initialize movies
    }

    public void destroy() {
        // cleanup movies
    }
}
Kotlin
@Configuration
class Config {
    
    @Bean
    fun storage(): MovieStorage {
        return MovieStorage()
    }
}

class MovieStorage {
    private val movies: List<String> = Collections.synchronizedList(ArrayList())

    fun init() {
        // initialize movies
    }

    fun destroy() {
        // cleanup movies
    }
}
Select one or more options from the list
___

Create a free account to access the full topic