Tag: spring

我可以为@Cacheable设置TTL吗?

我正在尝试Spring 3.1的@Cacheable批注支持,并想知道是否有任何方法可以通过设置一个TTL使caching的数据清除一段时间? 现在我可以看到,我需要使用@CacheEvict自己清除它,通过和@Scheduled一起使用,我可以自己做一个TTL实现,但对于这样一个简单的任务似乎有点多?

如何在春季testing中设置环境variables或系统属性?

我想写一些testing来检查部署的WAR的XML Springconfiguration。 不幸的是一些bean需要设置一些环境variables或系统属性。 在使用方便的testing样式和@ContextConfiguration时,如何在Spring bean初始化之前设置一个环境variables? @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:whereever/context.xml") public class TestWarSpringContext { … } 如果我使用注释来configuration应用程序上下文,那么在Spring上下文初始化之前,我没有看到一个可以做些什么的钩子。

如何从Spring获取当前用户区域设置而不将其作为parameter passing给函数?

我正在使用Spring 3.1,并希望find当前用户的语言环境有没有办法直接抓住语言环境,而不必被迫将其从控制器传递到服务层…等等。 spring存储区域设置在一个线程本地存储,它可以通过调用一些静态方法来抓取?

@Autowired和静态方法

我有@Autowired服务,必须在静态方法中使用。 我知道这是错误的,但我不能改变目前的devise,因为它需要很多工作,所以我需要一些简单的黑客。 我不能改变randomMethod()是非静态的,我需要使用这个autowired bean。 任何线索如何做到这一点? @Service public class Foo { public int doStuff() { return 1; } } public class Boo { @Autowired Foo foo; public static void randomMethod() { foo.doStuff(); } }

Spring.properties文件:将元素作为一个数组

我使用Spring从.properties文件加载属性属性如下: file: elements.properties base.module.elementToSearch=1 base.module.elementToSearch=2 base.module.elementToSearch=3 base.module.elementToSearch=4 base.module.elementToSearch=5 base.module.elementToSearch=6 spring的XML文件 file: myapplication.xml <bean id="some" class="com.some.Class"> <property name="property" value="#{base.module.elementToSearch}" /> </bean> 和我的Class.java file: Class.java public void setProperty(final List<Integer> elements){ this.elements = elements; } 但是在debugging的时候,参数元素只会把最后一个元素放到列表中,所以列表中只有一个值为“6”的元素,而不是一个有6个元素的列表。 我尝试了其他方法,比如仅添加值#{base.module}但是在属性文件中找不到任何参数。 解决方法是在elements.properties文件中用逗号分隔列表,如: base.module.elementToSearch=1,2,3,4,5,6 并用它作为一个string,并parsing它,但有没有更好的解决scheme?

如何注入ApplicationContext本身

我想将一个ApplicationContext本身注入到一个bean中。 就像是 public void setApplicationContext(ApplicationContect context) { this.context = context; } spring可能吗?

如何使用Spring Boot注册辅助servlet?

我有一个额外的servlet,我需要在我的应用程序中注册。 然而,使用Spring Boot及其Javaconfiguration文件,我不能在web.xml文件中添加servlet映射。 我怎样才能添加额外的servlet?

如何在Spring Security中禁用“X-Frame-Options”响应头?

我有我的jsp CKeditor,每当我上传的东西,popup以下错误: Refused to display 'http://localhost:8080/xxx/xxx/upload-image?CKEditor=text&CKEditorFuncNum=1&langCode=ru' in a frame because it set 'X-Frame-Options' to 'DENY'. 我试过删除Spring Security,一切都像一个魅力。 我怎样才能在春季安全xml文件禁用此? 我应该在<http>标签之间写什么?

Spring REST服务:如何configuration删除json响应中的空对象

我有一个返回json响应的spring webservice。 我使用这里给出的例子来创build服务: http : //www.mkyong.com/spring-mvc/spring-3-mvc-and-json-example/ json返回的格式是:{“name”:null,“staffName”:[“kfc-kampar”,“smith”]} 我想从返回的响应中删除任何空对象,如下所示:{“staffName”:[“kfc-kampar”,“smith”]} 我在这里发现类似的问题,但我已经能够得到一个解决scheme,例如 在Spring中configurationObjectMapper 如何在使用基于Spring注解的configuration时configurationMappingJacksonHttpMessageConverter? configurationjacksonObjectMapper不工作在springmvc 3 如何configurationspring mvc 3不返回json响应中的“null”对象? Springconfiguration@ResponseBody JSON格式 jackson+ Spring3.0.5自定义对象映射器 从阅读这些和其他来源,我想到了最简洁的方法来实现我想要的是使用Spring 3.1和可以在mvc注释中configuration的消息转换器。 我更新的springconfiguration文件是: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"> <context:component-scan base-package="com.mkyong.common.controller" /> <mvc:annotation-driven> <mvc:message-converters> <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> <property name="prefixJson" value="true" /> <property name="supportedMediaTypes" value="application/json" /> <property name="objectMapper"> <bean class="org.codehaus.jackson.map.ObjectMapper"> <property […]

我应该先学什么,Spring或Hibernate?

我刚刚开始学习Struts,我正在努力成为一名Java程序员,做一个好的市场。 我的下一个决定是select下一步学习Spring还是Hibernate? 还有,你们有什么build议或提示,我是好的? 提前致谢!