各位有一个问题,我想在spring中继承json-rpc然后自定义了bean在启动的时候加载并注册.可是按照网上 http://mazhihui.iteye.com/blog/1662897 的方法总是说java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.当我设置bean的scope之后有无法运行.请问下怎么办.以下是代码:
public class Register{
@Autowired
private HttpServletRequest request;
private String packages[];
public void init(){
for(String pack:packages){
Set<Class<?>> set = ClassUtil.getClasses(pack);
for(Class<?> clazz:set){
Annotation[] annotations = clazz.getAnnotations();
for(int i=0 ;i<annotations.length;i++){
if(annotations[i].annotationType().getName().equals(RPC.class.getName())){
RPC rpc = clazz.getAnnotation(RPC.class) ;
String name = rpc.name() ;
if("".equals(name)){
name = ClassUtil.getClassName(clazz) ;
}
JsonRpcRegister.registerObject(request, name, clazz) ;
/*JSONRPCBridge bridge = new JSONRPCBridge();
bridge.registerObject(name, clazz) ;*/
}
}
}
}
}
public String[] getPackages() {
return packages;
}
public void setPackages(String[] packages) {
this.packages = packages;
}
}
<bean class="com.test.rpc.Register" init-method="init" scope="prototype">
<property name="packages">
<list>
<value>com.fiz.enap</value>
</list>
</property>
</bean>
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
可能你没有把request绑定的提供服务的线程上,要再web.xml中配置以后才可以在Spring中使用,
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener>
</listener>
或者
<filter>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
<filter-name>requestContextListener</filter-name>
</filter>
<filter-mapping>
<filter-name>requestContextListener</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>