草庐IT

java - Spring原型(prototype)bean是否需要手动销毁?

我注意到我的原型(prototype)作用域Springbean的@PreDestroy钩子(Hook)没有被执行。我已经阅读了here这实际上是设计使然。Spring容器将销毁单例bean,但不会销毁原型(prototype)bean。我不清楚为什么。如果Spring容器将创建我的原型(prototype)bean并执行它的@PostConstruct钩子(Hook),为什么当容器关闭时它不会破坏我的bean?一旦我的Spring容器关闭,继续使用它的任何bean是否有意义?我看不到您想要在完成其bean之前关闭容器的场景。在容器关闭后是否可以继续使用原型(prototype)Spr

java - 由于缺少 EmbeddedServletContainerFactory bean,Spring 应用程序无法启动

我正在尝试在heroku上部署一个应用程序,但遇到了几个问题。该应用程序在我的IDE(Intellij)中运行,但是当我尝试使用“herokulocal-fProcfile.windows”运行它时,我收到此错误:11:30:03PMweb.1|2016-05-2423:30:03.491WARN10368---[main]ationConfigEmbeddedWebApplicationContext:Exceptionencounteredduringcontextinitialization-cancellingrefreshattempt:org.springframework

java - 如何禁用某个 bean 的 Spring Autowiring ?

jar(外部库)中有一些类在内部使用Spring。所以库类的结构如下:@ComponentpublicclassTestBean{@AutowiredprivateTestDependencydependency;...}并且库提供了构造对象的API:publicclassLibrary{publicstaticTestBeancreateBean(){ApplicationContextcontext=newAnnotationConfigApplicationContext(springConfigs);returncontext.getBean(TestBean);}}在我的应用

spring - 注入(inject)bean列表时,列表中的顺序是否与bean定义的顺序相同

@Service@Order(1)publicclassFooServiceimplementsIService{..}@Service@Order(2)publicclassBarServiceimplementsIService{..}是否保证下面列表中的顺序永远是{FooService,BarService}:@InjectprivateListservices;(同样的问题也适用于xml配置) 最佳答案 我猜不是,因为@Order不是通用注释。来自javadoc:NOTE:Annotation-basedorderingis

java - 如何在spring boot中使用@Bean为抽象类创建bean

我需要将旧式spring项目迁移到Springboot。假设下面的代码片段我必须迁移到Spring引导样式。我问,如何将下面的抽象bean转换为@Bean? 最佳答案 用纯Java编写你的抽象基类(没有任何Spring耦合):publicabstractclassAbstractClass{privateSample1sample1;privateSample2sample2;publicAbstractClass(Sample1sample1,Sample1sample2){this.sample1=sample1;this.sa

java - Spring 无法 Autowiring ,有多个 `` 类型的 bean

这是我的问题:我有一个基接口(interface)和两个实现类。并且一个Service类对基接口(interface)有依赖,代码是这样的:@ComponentpublicinterfaceBaseInterface{}@ComponentpublicclassClazzImplAimplementsBaseInterface{}@ComponentpublicclassClazzImplBimplementsBaseInterface{}而且配置是这样的:@ConfigurationpublicclassSpringConfig{@BeanpublicBaseInterfacecla

java - 如何在我的自定义 Wicket 模型类中注入(inject) Spring bean?

在自定义Wicket类中,与以下类似,我使用的是应由Spring注入(inject)的服务bean,如SpringBean注释定义(来自wicket-spring项目)。publicclassReportExportFileModelextendsAbstractReadOnlyModel{@SpringBean(name="reportService")ReportServicereportService;ReportDtoreportDto;ReportExportFileModel(ReportDtoreportDto){this.reportDto=reportDto;}@Ov

spring - 通过限定符从 ApplicationContext 中获取 bean

鉴于此代码:publicinterfaceService{}@Component@Qualifier("NotWanted")publicclassNotWantedServiceimplementsService{}@Component@Qualifier("Wanted")publicclassWantedServiceimplementsService{}AnnotationConfigApplicationContextctx=newAnnotationConfigApplicationContext();ctx.register(NotWantedService.class)

java - spring:使用@Autowired和context:component-scan自动连接原型(prototype)bean时如何使用非默认构造函数?

假设你有一个如下的原型(prototype)bean类:@Component@Scope("prototype")publicclassFoobar{privateStringfoo;publicFoobar(Stringfoo){this.foo=foo;}}那么,是否可以使用@Autowired将这样的bean连接到另一个类中,该类应该使用非默认构造函数Foobar(Stringfoo)来实例化bean?更新在上面的示例中,构造函数参数Stringfoo在应用程序上下文中不可用,而是动态的。因此,使用@Autowired注释构造函数,然后在上下文中的某处指定foo似乎不是一个理想的

java - 如何将包含 < 字符的字符串属性注入(inject) Spring bean?

我的DAO有以下bean定义-我收到错误-与元素类型“property”关联的属性“value”的值不能包含“ 最佳答案 由于Spring配置是一个XML文件,你需要转义根据XML语法: 关于java-如何将包含 https://stackoverflow.com/questions/10171183/