2012-05-06 52 views
0

我使用spring-roo來生成我的項目。我不知道這兩件事情是否相關,但在Controller中,註釋@Async或@Secure都不起作用。 對於@Secure: 我加<global-method-security secured-annotations="enabled"/>標籤的applicationContext-security.xml文件和修改的pom.xml以滿足依賴性,Controller中的Spring註解不起作用? @Secure和@Async都不起作用

<dependency> 
    <groupId>org.springframework.security</groupId> 
    <artifactId>spring-security-aspects</artifactId> 
    <version>3.0.5.RELEASE</version> 
</dependency> 

上述控制器的方法,我加了@Secured("ROLE_ADMIN")但無論什麼樣的作用每個人都可以訪問該方法。我錯過了哪些配置來使@Secure Active?

對於@Async: 在applicationContext.xml中,我在controller.java添加

​​

@Async 
private void justWait20seconds() { 
    try { 
     Thread.sleep(20000); 
    } catch (InterruptedException e) { 
     e.printStackTrace(); 
    } 
} 

我預計這種方法不會阻塞的主要方法,但它沒」噸。這2個標籤都在我的UserController.java中,我不知道它們是否被鏈接。誰能幫忙?

+2

這些註釋是否在'@ Service' bean中工作?或者,另一方面,嘗試將'

+0

Hello Tomasz,'* -servlet.xml'是什麼?在我的項目中,我沒有這樣的配置文件,那個文件裏有什麼? – JerryCai

回答

2

這聽起來像你不明白在Spring MVC應用程序中如何組織Spring上下文,並且將註釋處理指令添加到錯誤的上下文中。在Spring MVC中閱讀Spring上下文。你可以找到我的另一個SO答案分支到其他相關答案在:Why DispatcherServlet creates another application context?

0

我有同樣的問題,其中安全註釋工作在Roo項目的jspx的,但不是在控制器。我的修復是以下內容添加到webmvc-config.xml中:

<security:global-method-security secured-annotations="enabled" /> 

(加上這的applicationContext-security.xml文件,我沒有工作)

然後我說的依賴性在POM CGLIB。 xml:

<dependency> 
    <groupId>cglib</groupId> 
    <artifactId>cglib</artifactId> 
    <version>2.2</version> 
</dependency>