使用spring的时候
报错信息为:
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.
简单的说就是没有找到对应的request请求。
此次报错过程是:
controller 里面用Thread执行service,service异常抛出自定义异常,拦截器拦截异常,并打印traceId信息,这个trace工具类,需要request对象。但是找不到所以报错。
这次的错误是因为抛出的异常类型不对。
因为自定义业务异常类型有很多种,如systemException,requestException等,不同的异常,处理方式也不同。 如果抛出requestException,需要从request中获取请求信息,找不到就报错。
没有request对象的常用场景是:
1、controller里面使用普通的Thread线程,这个线程是异步的,并没有request对象。
2、定时任务中也会有同样的问题,因为它不是基于请求的。并没有request对象。
但没有request对象和报错并没有必然联系,我的错误就是抛的自定义异常会经过调用request的拦截器。
通用方案:
修改抛出的异常类型为正确的类型。
controller中使用多线程:
如果controller中一定要使用Thread,那么可以用spring那个线程类,能够带request。
定时任务中:
定时任务中没法了,定时没有request,不要抛带request处理的异常即可。
使用背景:今天在spring-cloud项目中,使用多线程异步调用微服务出现的错误
Nothread-bound
request
found:Areyou
ref
erring
to
request
attributes
outs
ide
ofan
actual
web
request
,orprocessinga
request
outs
ide
oftheoriginallyr...
解决No thread-bound
request
found问题
今天遇到了启动项目时突然报找不到线程绑定请求:No thread-bound
request
found: Are you
ref
erring
to
request
attributes
outs
ide
of an
actual
web
request
, or processing a
request
outs
ide
of the originally receiving thread? If you are
actual
ly operat
场景描述:A服务利用RPC 调用B 服务, B 服务里请求了一个C服务的接口, 但是C服务需要接口授权,利用 HttpServlet
Request
request
= ((Servlet
Request
Attributes
) (
Request
ContextHolder.current
Request
Attributes
())).get
Request
();解决: 换一中授权方式,直接生成了一个授权token, 不用
Request
ContextHolder 这种方式获取请求token。
分布式项目中,我们会把一些服务提取出来形成一个服务提供者,并且单独发布为一个项目。一般发布成一个jar包,这个服务提供者可以称之为 soa项目。
soa只是一个简单的接口项目,不是
web
...
We report a photoluminescence observation of the coupling of donor-bound excitons and longitudinal optical phonons in high-quality ZnO crystals at 5 K. The first-order phonon Stockes line of donor-bound excitons exhibits a distinct asymmetric line shape with a clear dip at its higher energy s
ide
, suggesting that quantum mechanical interference occurs during the annihilation of donor-bound excitons. The donor binding energy is determined to be 49.3 meV from spectral featural.
异常信息:
java.lang.IllegalStateException: No thread-bound
request
found: Are you
ref
erring
to
request
attributes
outs
ide
of an
actual
web
request
, or processing a
request
outs
ide
of the originally receiving thread? If you are
actual
ly operating within a
web
r
在一个项目中需要实现一个定时上报的任务,由于是分条件上报所以就采用了异步的上报方式,用了自定义的线程池运行上报线程。定时任务执行的时候报了No thread-bound
request
found: " + "Are you
ref
erring
to
request
attributes
outs
ide
of an
actual
web
request
, " + "or processing a
request
outs
ide
of the originally recei
No thread-bound
request
found: " +
"Are you
ref
erring
to
request
attributes
outs
ide
of an
actual
web
request
, " +
"or processing a
request
outs
ide
of the originally receiving thread?
Servlet
Request
Attributes
servlet
Request
Attributes
= (Servlet
Request
Attributes
)
Request
ContextHolder.get
Request
Attributes
();
CompletableFuture.supplyAsync(() -> {
Request
ContextHolder.set
Request
Attributes
(servlet
Request
Attrib.
异常:Caused by: java.lang.IllegalStateException: Method has too many Body parameters
Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract com.iot.framework.core.response.CommResponse
com.iot.basic.config.api.client.configdata.PushRuleClient.getByEven
First Edition
LATEX is a beautiful programming language. One sometimes wants to write in an easy and quick way various documents, such as letters, papers, reports, theses, and so on. Here, “one” can be a new student, an old professor, or even somebody who is not linked at all with any academic stuff.
We often want special constructs in our documents. This is more difficult than basic typesetting, especially using LATEX when you are not experienced.
On one hand, scientists do not always have the time to learn another programming language, especially if they are making a PhD, or doing something else which asks for a lot of time. Using direct and working programming tricks can speed up your productivity, and make you learning better. But where can they be found?
On the other hand, everybody wants to make nice documents, if possible.
A nicer document attracts the reader. Ev
ide
ntly, “a nice document” is a subjective notion. By “nice document,” we want to speak about a document which
1. is structured in an unambiguous way, and has a clear presentation, 2. is read with pleasure, if possible.
The beginner, whoever he is, often faces strange errors because he tries to teach LATEX to do what he wants it to do. It is difficult to learn the advanced notions about LATEX, even in an average period of time. The good books have to be found. But that is often the moment where you lack of time and that you are happy to find complete solutions. That is a moment where you tell to yourself “Is there no folk out there to give me such a trivial tip?” but nobody hears it. The aim of this book, is to avoid you these problems: you do not need to write everything from scratch, ask on various forums or Usenet groups, or even read heaps of books just to make a simple script. That is my goal. You can now continue writing your document in LATEX’s philosophy: concentrating on your document’s content, at the place of its appearence.XX P
ref
ace
These reasons justify the presence of this book. I have tried to pack the most useful tricks which can enhance your documents’ content in a concise way. The aim is not to teach LATEX programming, but to give a quick
ref
erence to all the tips and tricks that can be used if you are encountering a (difficult) problem, or simply facing a question which you cannot find the answer to.
I cons
ide
r that the reader is familiar with basic LATEX programming. It can be learnt from various sources: [22, 28, 47, 55, 59, 97, 165, 175], and many others.
In many book(let)s, a part is always devoted to tell how the reader should read the book. It is, at least to me, often too directive. Here is the way I propose you to read this booklet. Firstly, have a look at the table of contents.
Many different subjects are treated in this booklet, and reading them from one to another, until the end, could be really boring. You may, after having read the table of contents, roughly check the two parts, and then begin to read what you need to read. If you simply want to learn something about a particular subject, you will find this booklet very useful. On the other hand, if you want to read everything, you can, but the structure of the document has not been thought for such a reading scheme. Depending on your degree of knowledge with LATEX, you can 1. either read everything, because you do not know a lot about this, 2. or read particular subjects,
ref
erring
to the outline, to deepen your knowledge.
I hope this will give you new
ide
as about advanced ways to typeset text and to make different processes automatic, thus giving you more time for other activities.
If you have any suggestion, whatever the topic, feel free to send me an e-mail at
mluca@swing.be
Li`ege, Luca Merciadri
October, 2009