草庐IT

Bean-IOC

全部标签

java - 如何在 Spring WebApplicationContext 中在运行时添加 bean 实例?

所以,标题很简单。我有一个处理程序类DynamicBeanHandler,它实现了spring提供的BeanDefinitionRegistryPostProcessor接口(interface)。在这个类中,我添加了多个SCOPE_SINGLETONbean,它们的bean类设置为MyDynamicBean,如下所示-GenericBeanDefinitionmyBeanDefinition=newGenericBeanDefinition();myBeanDefinition.setBeanClass(MyDynamicBean.class);myBeanDefinition.se

java - 捕捉spring初始化所有bean的时刻

我有spring应用程序(我没有懒bean)。我想在所有@Component(@Repositoey@Service@Controller)bean初始化时插入逻辑。我该怎么做? 最佳答案 如thisquestion的回答中所述,您可以使用ApplicationListener并查找ContextRefreshedEvent:publicclassLoaderimplementsApplicationListener{publicvoidonApplicationEvent(ContextRefreshedEventevent){/

java - 捕捉spring初始化所有bean的时刻

我有spring应用程序(我没有懒bean)。我想在所有@Component(@Repositoey@Service@Controller)bean初始化时插入逻辑。我该怎么做? 最佳答案 如thisquestion的回答中所述,您可以使用ApplicationListener并查找ContextRefreshedEvent:publicclassLoaderimplementsApplicationListener{publicvoidonApplicationEvent(ContextRefreshedEventevent){/

java - 带有注释的Bean定义继承?

是否可以使用基于注解的配置(@Bean等)实现相同的bean继承?http://docs.spring.io/spring/docs/4.1.0.BUILD-SNAPSHOT/spring-framework-reference/htmlsingle/#beans-child-bean-definitions 最佳答案 javaconfig中没有抽象bean的概念,因为java语言已经拥有你需要的一切。不要忘记抽象bean根本没有暴露在上下文中,它是某种模板。您可以将上面的代码改写如下:@Configurationpubliccla

java - 带有注释的Bean定义继承?

是否可以使用基于注解的配置(@Bean等)实现相同的bean继承?http://docs.spring.io/spring/docs/4.1.0.BUILD-SNAPSHOT/spring-framework-reference/htmlsingle/#beans-child-bean-definitions 最佳答案 javaconfig中没有抽象bean的概念,因为java语言已经拥有你需要的一切。不要忘记抽象bean根本没有暴露在上下文中,它是某种模板。您可以将上面的代码改写如下:@Configurationpubliccla

java - Spring boot - 由于缺少 EmbeddedServletContainerFactory bean,无法启动 EmbeddedWebApplicationContext

Spring启动我试图在intelliJ中运行我的SpringBoot应用程序,但出现错误:._________/\\/___'_____(_)______\\\\(()\___|'_|'_||'_\/_`|\\\\\\/___)||_)|||||||(_||))))'|____|.__|_||_|_||_\__,|////=========|_|==============|___/=/_/_/_/::SpringBoot::(v1.3.1.RELEASE)2016-01-2623:09:30.883INFO3960---[main]com.example.he.ExampleApp

java - Spring boot - 由于缺少 EmbeddedServletContainerFactory bean,无法启动 EmbeddedWebApplicationContext

Spring启动我试图在intelliJ中运行我的SpringBoot应用程序,但出现错误:._________/\\/___'_____(_)______\\\\(()\___|'_|'_||'_\/_`|\\\\\\/___)||_)|||||||(_||))))'|____|.__|_||_|_||_\__,|////=========|_|==============|___/=/_/_/_/::SpringBoot::(v1.3.1.RELEASE)2016-01-2623:09:30.883INFO3960---[main]com.example.he.ExampleApp

spring - MyBatis-Spring + @Configuration - 无法 Autowiring 映射器 bean

我一直在尝试创建一个使用MyBatis作为数据访问层的Spring项目,作为我团队的概念证明。如果可能的话,我真的想避免XML配置,所以我尝试使用带注释的@Configuration类将所有内容连接在一起。一切似乎都已正确连接,但我的映射器bean并未自动连接到我的服务层。在我的示例中,我尝试将UserDao、User实体和UserService连接在一起。UserDaopublicinterfaceUserDao{@Select("SELECT*FROMusersWHEREid=#{userId}")Userget(@Param("userId")IntegeruserId);}用户

spring - MyBatis-Spring + @Configuration - 无法 Autowiring 映射器 bean

我一直在尝试创建一个使用MyBatis作为数据访问层的Spring项目,作为我团队的概念证明。如果可能的话,我真的想避免XML配置,所以我尝试使用带注释的@Configuration类将所有内容连接在一起。一切似乎都已正确连接,但我的映射器bean并未自动连接到我的服务层。在我的示例中,我尝试将UserDao、User实体和UserService连接在一起。UserDaopublicinterfaceUserDao{@Select("SELECT*FROMusersWHEREid=#{userId}")Userget(@Param("userId")IntegeruserId);}用户

spring - 2个同名但在不同包中的bean;如何自动接线?

我有一个应用程序,它有2个同名的bean,但它们位于不同的包中。我的Spring应用程序失败,因为它无法决定采用哪个bean。有什么解决办法吗?bean目前没有实现特定的接口(interface)。请参见下面的异常编辑示例:Causedby:org.springframework.context.annotation.ConflictingBeanDefinitionException:Annotation-specifiedbeanname'dataTransferHandler'forbeanclass[aaaaa.ws.handler.DataTransferHandler]co