Spring AOP注入PortletRequest
我试图在我的方面类中注入一个 portletrequest
@Autowired(required = true)
private PortletRequest request;
@Before("execution(* de.ac.mis.dao.*.getSessionFactory())")
public void setUsername() {
System.out.println("Now I'm setting the username " + this.request);
}
只给我一个
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No matching bean of type [javax.portlet.PortletRequest] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
例外
,但我可以自动装配 HttpServletRequest
- 我错过了什么吗?
I'm trying to inject a portletrequest in my aspect class
@Autowired(required = true)
private PortletRequest request;
@Before("execution(* de.ac.mis.dao.*.getSessionFactory())")
public void setUsername() {
System.out.println("Now I'm setting the username " + this.request);
}
Only gives me an
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No matching bean of type [javax.portlet.PortletRequest] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
exception
but I can autowire HttpServletRequest
- am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,经过一些实验后解决了这个问题,也许对其他人有用。
对于这些配置来说,重要的是请求资源(portlet 或 servlet)必须在 spring 上下文中运行,否则此时没有可用的请求属性。
Okay solved it after some experimenting, maybe it could be useful for someone else
Important for these config is that the requesting resources (portlets or servlets) must run in spring context else no requestattributes are available at this point.
在查看了 JavaDocs 后,我选择使用 resolveReference,它声称:
示例代码:
I opted to use resolveReference after looking at the JavaDocs, which claims:
Example Code: