这是我面临的挑战:
我有一个servlet程序.我需要将每个用户的日志写入以该用户命名的文件夹.像这样的东西:
// stores message to David folder
// /root_path/David/logfile.log
logger.error(MarkerManager.getMarker("David"), "Error happened");
// stores message to Mark folder
// /root_path/Mark/logfile.log
logger.error(MarkerManager.getMarker("Mark"), "Something is broken");
Run Code Online (Sandbox Code Playgroud)
在我的例子中,我使用了标记.但我真的不知道标记是否适合这项任务.
通常,我的appender应该像RollingRandomAccessFile appender一样.我想apppen for appender看起来像这样:
<RollingRandomAccessFile name="rollingFile"
fileName="logs/{markerName ?????}/movie-db.log"
filePattern="logs/log-%d{yyyy-MM-dd}-%i.log.zip"
append="false"
immediateFlush="false"
ignoreExceptions="true">
<PatternLayout pattern="%d{ISO8601} %level{length=5} [%thread] %logger - %msg%n"/>
<Policies>
<SizeBasedTriggeringPolicy size="25 MB"/>
<TimeBasedTriggeringPolicy />
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingRandomAccessFile>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我有问题,我想将我的Spring WebMVC应用程序的一些进程外包到单独的Threads中.这很容易并且有效,直到我想使用一个使用全局请求的类userRightService.这在线程中不可用,我们遇到了一个问题,这几乎是可以理解的.
这是我的错误:
java.lang.RuntimeException:
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'scopedTarget.userRightsService': Scope 'request' is not active
for the current thread; consider defining a scoped proxy for this bean if
you intend to refer to it from a singleton; nested exception is
java.lang.IllegalStateException: Cannot ask for request attribute -
request is not active anymore!
Run Code Online (Sandbox Code Playgroud)
好的,够清楚了.我试图通过实现此解决方案来保持请求上下文:
这是我的runnable类:
@Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class myThread implements Runnable {
private RequestAttributes context;
public DataExportThread(RequestAttributes context) {
this.context = context;
}
public …Run Code Online (Sandbox Code Playgroud)