12得票2回答
如何通过Java配置以正确的方式激活CommonAnnotationBeanPostProcessor中的@PostConstruct?

我正在使用Spring 4与SpringBoot和Spring-Web,采用Java配置方式。为了让我的@PostConstruct注释的方法在启动时由Spring执行,有必要在上下文中注册CommonAnnotationBeanPostProcessor,否则@PostConstruct将被...

13得票2回答
Spring基于注解的配置 - 内存消耗过高?

我注意到我的客户端应用程序(基于Swing)使用了非常高的RAM,因此开始研究它,似乎这与Spring中的基于注解的配置有关。如下所示,我意识到这仅在64位JVM上发生。 请参阅以下测试代码: 基于XML的配置<beans ....> <bean id="xml...

50得票1回答
在Spring框架中,是否可以使用注释来设置Bean的名称?

我有一个像这样的豆子:@Bean public String myBean(){ return "My bean"; } 我想进行自动装配:@Autowired @Qualifier("myBean") public void setMyBean(String myBean){ ...

9得票5回答
Spring自动装配的bean导致空指针异常。

我有一个记录器类,它使用服务。每次创建新的记录器时,我希望能够访问单例作用域的日志记录服务。 我将日志记录服务自动装配到记录器中,但是返回了空指针异常。我尝试了一些解决方案: 1.在应用程序上下文中手动定义bean, 2.尝试让记录器成为Spring管理的对象,但这只会导致更多问题。 我...

12得票2回答
过于热衷的类型匹配结果 - 考虑使用“getBeanNamesOfType”并关闭“allowEagerInit”标志。

org.springframework.beans.factory.BeanCurrentlyInCreationException: 创建名为org.springframework.cache.annotation.AnnotationCacheOperationSource#0的bean时...

21得票3回答
在构造函数上使用@Resource注解是否可行?

我想知道是否可以在构造函数上使用 @Resource 注释。 我的使用情况是我想要连接一个名为 bar 的 final 字段。public class Foo implements FooBar { private final Bar bar; @javax.annota...

74得票5回答
自从Spring Boot框架中的@SpringApplicationConfiguration和@WebIntegration标注被弃用,应该使用哪种合适的注释?

自 Spring Boot Framework 1.4 开始,@SpringApplicationConfiguration 和 @WebIntegration 已被弃用,请问正确的注释方式是什么?我想尝试进行单元测试。

37得票8回答
Spring Boot @Value 属性配置

我有一个Spring Boot应用程序,在其中一个类中,我尝试使用@Value引用来自application.properties文件的属性。但是,该属性未得到解析。我已查看了类似的帖子并尝试按照建议操作,但这并没有帮助我。这个类是:@Configuration @ComponentScan ...

9得票3回答
Spring Security 4 @PreAuthorize(hasAuthority())访问被拒绝。

我将尝试将Spring Security 3中的@Secured("admin")注释转换为与Spring Security 4兼容的格式。 这是我的usersService.java文件。 @PreAuthorize("hasAuthority('admin')") public Lis...