This article mainly introduces JSP JSP information related to the dynamic creation of beans in the development of Spring Boot. Friends who are interested in JSP can refer to this article
Spring Boot for JSP development dynamically creates Bean
1. Create
a through the annotation @Import import method and create a new MyImportBeanDefinitionRegistrar registration center
Java code
import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.GenericBeanDefinition; import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; import org.springframework.core.type.AnnotationMetadata; import web0.services.Myservice; public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar { protected String BEAN_NAME = "myservice"; public void dynamicConfiguration() throws Exception { } @Override public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { if (!registry.containsBeanDefinition(BEAN_NAME)) { GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(Myservice.class); beanDefinition.setSynthetic(true); registry.registerBeanDefinition(BEAN_NAME, beanDefinition); } } }
b. Add @Import to the configuration class to introduce the above class
@Import(MyImportBeanDefinitionRegistrar.class) public class TestConfig{ }
c. After this operation, you can use spring
The above is a simple example of dynamically creating a bean in Spring Boot in JSP. If you have any questions, please leave a message or go to the community of this site for discussion! !
Related recommendations:
Detailed introduction to Spring boot and an example of adding jsp support configuration
Detailed introduction to jsp page jump
The parameters of the form submitted in jsp are encapsulated into a method
The above is the detailed content of Spring Boot for JSP development dynamically creates beans. For more information, please follow other related articles on the PHP Chinese website!