Tag: spring annotations

Struts2 + Spring Security 2.06:尝试在Action方法上使用@Secured时,Valuestack为null

在开始之前,我要说我发现的最接近的答案就是在这里,但老实说,我并不真正了解那里发生了什么。 我正在使用带有自定义身份validation提供程序和访问决策pipe理器的Struts2 + Spring Security 2.06来删除“ROLE_”前缀的需要。 我的applicationContext-security.xml如下所示: <beans:bean id="customAuthenticationProvider" class="com.test.testconsole.security.CustomAuthenticationProvider"> <beans:property name="userManagementService" ref="userManagementService"/> <custom-authentication-provider/> </beans:bean> <!–Customize Spring Security's access decision manager to remove need for "ROLE_" prefix–> <beans:bean id="accessDecisionManager" class="org.springframework.security.vote.AffirmativeBased"> <beans:property name="decisionVoters"> <beans:list> <beans:ref bean="roleVoter"/> <beans:ref bean="authenticatedVoter"/> </beans:list> </beans:property> </beans:bean> <beans:bean id="roleVoter" class="org.springframework.security.vote.RoleVoter"> <beans:property name="rolePrefix" value=""/> </beans:bean> <beans:bean id="authenticatedVoter" class="org.springframework.security.vote.AuthenticatedVoter"> </beans:bean> <global-method-security secured-annotations="enabled" access-decision-manager-ref="accessDecisionManager"/> 我的web.xml的相关部分: […]

在unit testing期间填充Spring @Value

我正在为我的程序中使用的一个简单的bean编写unit testing来validation表单。 该bean用@Component注解,并有一个类variables,它是使用@Value("${this.property.value}") private String thisProperty;初始化@Value("${this.property.value}") private String thisProperty; 我想为这个类中的validation方法编写unit testing,但是,如果可能的话,我想这样做,而不使用属性文件。 我背后的推理是,如果我从属性文件拉的值发生变化,我希望不会影响我的testing用例。 我的testing用例正在testingvalidation值的代码,而不是值本身。 有没有一种方法可以在我的testing类中使用Java代码来初始化Java类,然后在该类中填充Spring @Value属性,然后使用它来testing? 我没有find这个如何似乎是接近,但仍然使用属性文件。 我宁愿这一切都是Java代码。 谢谢

春季4 – addResourceHandlers不parsing静态资源

下面显示了我的maven spring项目目录结构。 我正在使用Spring-4基于注释的configuration。 我configuration下面的资源。 我尝试了许多Stackoverflow问题和其他网站的build议 Spring 4加载静态资源 http://imwill.com/spring-mvc-4-add-static-resources-by-annotation/#.U5GZlXKs9i4 但是jsp文件无法加载资源,所有的静态内容请求都返回404错误。 我在jsp上试过这些东西, <link href="resources/css/bootstrap.css" rel="stylesheet" media="screen"> <link href="/resources/css/bootstrap.css" rel="stylesheet" media="screen"> <link href="css/bootstrap.css" rel="stylesheet" media="screen"> 编辑:我正在使用servlet 2.5,因为截至目前我无法将我的项目从JBoss 5升级到更高版本。 JBoss5不支持servlet 3,这是否重要? @Configuration @ComponentScan("com.mgage.mvoice") public class MyAppWebConfig extends WebMvcConfigurerAdapter { public void addResourceHandlers(ResourceHandlerRegistry registry) { // I tried these many combinations separately. ResourceHandlerRegistration resourceRegistration = registry .addResourceHandler("resources/**"); resourceRegistration.addResourceLocations("/resources/**"); registry.addResourceHandler("/css/**").addResourceLocations("/css/**"); registry.addResourceHandler("/img/**").addResourceLocations("/img/**"); […]