更改Spring-Shell.Log位置



我的spring-shell.log遇到了一些麻烦。这不是一个大问题,但真的很烦人。从工作区外部运行应用程序后,Spring Shell会尝试将Springshell.log保存在受Windows保护的目录中。这导致没有Shelö历史。现在,我只是想保存文件

我最喜欢的方法是通过application.properties更改位置。但是我不知道是否有属性。我还可以更改logback-spring.xml。

java.nio.file.AccessDeniedException: C:Windowsspring-shell.log
        at sun.nio.fs.WindowsException.translateToIOException(Unknown Source) ~[na:1.8.0_191]
        at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source) ~[na:1.8.0_191]
        at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source) ~[na:1.8.0_191]
        at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(Unknown Source) ~[na:1.8.0_191]
        at java.nio.file.spi.FileSystemProvider.newOutputStream(Unknown Source) ~[na:1.8.0_191]
        at java.nio.file.Files.newOutputStream(Unknown Source) ~[na:1.8.0_191]
        at java.nio.file.Files.newBufferedWriter(Unknown Source) ~[na:1.8.0_191]
        at java.nio.file.Files.newBufferedWriter(Unknown Source) ~[na:1.8.0_191]
        at org.jline.reader.impl.history.DefaultHistory.save(DefaultHistory.java:121) ~[jline-3.4.0.jar!/:na]
        at org.jline.reader.impl.history.DefaultHistory.add(DefaultHistory.java:248) ~[jline-3.4.0.jar!/:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_191]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_191]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_191]
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) [spring-aop-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:205) [spring-aop-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
        at com.sun.proxy.$Proxy52.add(Unknown Source) [na:na]
        at org.jline.reader.impl.LineReaderImpl.finishBuffer(LineReaderImpl.java:864) [jline-3.4.0.jar!/:na]
        at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:557) [jline-3.4.0.jar!/:na]
        at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:390) [jline-3.4.0.jar!/:na]
        at org.springframework.shell.jline.InteractiveShellApplicationRunner$JLineInputProvider.readInput(InteractiveShellApplicationRunner.java:115) [spring-shell-core-2.0.1.RELEASE.jar!/:2.0.1.RELEASE]
        at org.springframework.shell.Shell.run(Shell.java:129) [spring-shell-core-2.0.1.RELEASE.jar!/:2.0.1.RELEASE]
        at org.springframework.shell.jline.InteractiveShellApplicationRunner.run(InteractiveShellApplicationRunner.java:84) [spring-shell-core-2.0.1.RELEASE.jar!/:2.0.1.RELEASE]
        at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:770) [spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:760) [spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:318) [spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213) [spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202) [spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at com.provinzial.convenience.tools.Application.main(Application.java:12) [classes!/:0.0.1-SNAPSHOT]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_191]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_191]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_191]
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:47) [convenience-tools-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:86) [convenience-tools-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [convenience-tools-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [convenience-tools-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]

我感谢任何提示。多谢你们。最好的问候,塞巴斯蒂安

在您的春季项目中,只需创建一个新类:

package com.example.shell.demo.config;
import org.jline.reader.History;
import org.jline.reader.LineReader;
import org.jline.reader.impl.history.DefaultHistory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.EventListener;
import java.io.IOException;
import java.nio.file.Paths;
@Configuration
public class HistoryConfiguration {
    @Autowired
    private History history;
    @Bean
    public History history(LineReader lineReader, @Value("${app.history.file}") String historyPath) {
        lineReader.setVariable(LineReader.HISTORY_FILE, Paths.get(historyPath));
        return new DefaultHistory(lineReader);
    }
    @EventListener
    public void onContextClosedEvent(ContextClosedEvent event) throws IOException {
        history.save();
    }
}

然后,在您的application.properties文件中,创建一个按下键/值对

app.history.file=<path to your log file>

原始解决方案在此处发布:https://github.com/spring-projects/spring-shell/issues/220。我已经用弹簧壳2.0.0释放进行了测试,并且效果很好。

希望会有所帮助。

最新更新