包名:com.sample
SpringMain.java
@SpringBootApplication
@ComponentScan
public class SpringMain implements CommandLineRunner
{
@Autowired
SampleClass sampleClass;
public static void main(String[] args) {
SpringApplication.run(SpringMain.class, args);
}
@Override
public void run(String... args) throws Exception
{
sampleClass.callThread();
}
}
Run Code Online (Sandbox Code Playgroud)
包名称:com.sample.infra
示例类.java
@Component
public class SampleClass
{
@Autowired
ThreadSample threadSample;
public void callThread()
{
System.out.println("Inside SampleClass");
threadSample.start();
}
}
Run Code Online (Sandbox Code Playgroud)
包名称:com.sample.dao
线程示例.java
@Component
public class ThreadSample extends Thread
{
@Autowired
JdbcTemplate jdbcTemplate;
public void run()
{
init();
}
public String init()
{
System.out.println("Inside ThreadSample");
SimpleJdbcCall jdbcCall = new …Run Code Online (Sandbox Code Playgroud) 我的詹金斯装在 C:\Program Files (x86)\Jenkins
bat文件位于 C:\Users\Admin\workspace\demoWork\run.bat
当我从cmd运行此bat文件时,一切正常。但是当我尝试从jenkins执行Image中提到的批处理命令时,Jenkins显示错误为
构建步骤“执行Windows批处理命令”将构建标记为失败
同样,在jenkins文件夹中,会自动用工作标题名称创建工作区文件夹。你们能详细解释一下吗
log4j2.xml
我已经检查了有关此错误的几个问题,但我无法弄清楚为什么数据没有写入日志文件。
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<RollingRandomAccessFile name="HzServer"
filename="logs/hzServer.log" immediateFlush="false" append="true"
filepattern="logs/hzServer.log-%d{MM-dd-yyyy}">
<PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} %highlight{%level}{FATAL=bg_red, ERROR=red, WARN=yellow, INFO=green, DEBUG=blue} - %msg%throwable%n" />
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="100 MB" />
</Policies>
<DefaultRolloverStrategy max="20" />
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<Logger name="com.example" level="debug" includeLocation="true"
additivity="false">
<AppenderRef ref="HzServer" />
</Logger>
</Loggers>
</Configuration>
Run Code Online (Sandbox Code Playgroud)
pom.xml
配置似乎没问题,甚至依赖项也已检查。
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.8.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
文件 …