Questions tagged «spring-java-config»

7
Spring Java Config:如何创建带有运行时参数的原型作用域@Bean?
使用Spring的Java Config,我需要使用只能在运行时获得的构造函数参数来获取/实例化作用域原型的bean。考虑以下代码示例(为简便起见,对其进行了简化): @Autowired private ApplicationContext appCtx; public void onRequest(Request request) { //request is already validated String name = request.getParameter("name"); Thing thing = appCtx.getBean(Thing.class, name); //System.out.println(thing.getName()); //prints name } Thing类的定义如下: public class Thing { private final String name; @Autowired private SomeComponent someComponent; @Autowired private AnotherComponent anotherComponent; public Thing(String name) { this.name …

8
在RESTful和Spring Boot / MVC / JavaConfig中使用GZIP压缩
我们将Spring Boot / MVC与基于注释的java-config一起用于一系列RESTful服务,并且我们希望选择性地HTTP GZIP对某些API响应启用流压缩。 我知道我可以在控制器和a中手动完成此操作byte[] @ResponseBody,但是我们更希望依靠SpringMVC基础结构(过滤器/等)并让它自动进行JSON转换和压缩(即该方法返回POJO)。 如何在ResponseBody或嵌入式Tomcat实例中启用GZIP压缩,并且以某种方式我们可以选择性地仅压缩某些响应? 谢谢! PS .:我们目前没有任何基于XML的配置。

2
如何在自定义过滤器中使用Java配置注入AuthenticationManager
我正在使用Spring Security 3.2和Spring 4.0.1 我正在将xml配置转换为Java配置。当我在“过滤器”中添加注释AuthenticationManager时@Autowired,出现异常 Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.authentication.AuthenticationManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} 我已经尝试了注入,AuthenticationManagerFactoryBean但是由于类似的异常也失败了。 这是我正在使用的XML配置 <?xml version="1.0" encoding="UTF-8"?> <beans ...> <security:authentication-manager id="authenticationManager"> <security:authentication-provider user-service-ref="userDao"> <security:password-encoder ref="passwordEncoder"/> </security:authentication-provider> </security:authentication-manager> <security:http realm="Protected …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.