Here is a simple code:
ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
beanFactory.registerSingleton(bean.getClass().getCanonicalName(), bean);
More Related Contents:
- Exception NoClassDefFoundError for CacheProvider
- Spring – No EntityManager with actual transaction available for current thread – cannot reliably process ‘persist’ call
- Initializing Log4J with Spring?
- Role/Purpose of ContextLoaderListener in Spring?
- Deploying Spring 5.x on Tomcat 10.x
- Spring MVC – How to get all request params in a map in Spring controller?
- Spring Data JPA – ZonedDateTime format for json serialization
- What is the difference between @Inject and @Autowired in Spring Framework? Which one to use under what condition?
- Using JFreeChart to display recent changes in a time series
- Spring CrudRepository findByInventoryIds(List inventoryIdList) – equivalent to IN clause
- Spring Cache with collection of items/entities
- Howto get rid of ?
- Spring: Standard Logging aspect (interceptor)
- Spring WebSocket @SendToSession: send message to specific session
- In Spring MVC, how can I set the mime type header when using @ResponseBody
- request scoped beans in spring testing
- Manually call Spring Annotation Validation
- Spring: Make sure a particular bean gets initialized first
- Spring/Java error: namespace element ‘annotation-config’ … on JDK 1.5 and higher
- Spring forward with added parameters?
- Spring Security multiple url ruleset not working together
- Return a stream with Spring MVC’s ResponseEntity
- Spring Boot access static resources missing scr/main/resources
- How to modify request body before reaching controller in spring boot
- What are annotations and how do they actually work for frameworks like Spring?
- How to set up multi-threading in Spring Batch?
- RestTemplate with pem certificate
- java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet error
- Can we declare spring bean conditionally?
- Spring MVC: How to modify json response sent from controller