我目前面临 Spring 1.4.2 项目的问题。
当我在 IntelliJ 中运行我的项目时,一切正常(使用 java --classpath com.my.project.Launcher)。 但是,当我生成 jar 并手动运行它时,我得到以下堆栈跟踪。
2024-10-02 16:50:24 [background-preinit] INFO [org.hibernate.validator.internal.util.Version] Version.<clinit>:30 - HV000001: Hibernate Validator 5.2.4.Final
2024-10-02 16:50:24 [main] INFO [com.my.project.Launcher] StartupInfoLogger.logStarting:48 - Starting Launcher v3.1-SNAPSHOT on localhost.localdomain with PID 12995 (/home/user/workspace/my.project/target/my.project.jar started by user in /home/user/workspace/my.project)
2024-10-02 16:50:24 [main] INFO [com.my.project.batch.my.project.Launcher] SpringApplication.logStartupProfileInfo:661 - No active profile set, falling back to default profiles: default
2024-10-02 16:50:24 [main] INFO [org.springframework.context.annotation.AnnotationConfigApplicationContext] AbstractApplicationContext.prepareRefresh:582 - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@244038d0: startup date [Wed Oct 02 16:50:24 CEST 2024]; root of context hierarchy
2024-10-02 16:50:25 [main] INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] DefaultListableBeanFactory.registerBeanDefinition:821 - Overriding bean definition for bean 'transactionManager' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=myprojectTransactionManagerConfiguration; factoryMethodName=transactionManager; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/my/project/batch/my.project/configuration/MyProjectTransactionManagerConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration; factoryMethodName=transactionManager; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/batch/core/configuration/annotation/SimpleBatchConfiguration.class]]
2024-10-02 16:50:25 [main] WARN [org.springframework.context.annotation.ConfigurationClassEnhancer] ConfigurationClassEnhancer$BeanMethodInterceptor.intercept:348 - @Bean method ScopeConfiguration.stepScope is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean javadoc for complete details.
2024-10-02 16:50:25 [main] WARN [org.springframework.context.annotation.ConfigurationClassEnhancer] ConfigurationClassEnhancer$BeanMethodInterceptor.intercept:348 - @Bean method ScopeConfiguration.jobScope is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean javadoc for complete details.
2024-10-02 16:50:25 [main] WARN [com.atomikos.jdbc.AbstractDataSourceBean] Slf4jLogger.logWarning:12 - AtomikosDataSoureBean 'data1Ds': poolSize equals default - this may cause performance problems!
2024-10-02 16:50:26 [main] WARN [com.atomikos.jdbc.AbstractDataSourceBean] Slf4jLogger.logWarning:12 - AtomikosDataSoureBean 'data2Ds': poolSize equals default - this may cause performance problems!
2024-10-02 16:50:26 [main] WARN [com.atomikos.icatch.config.UserTransactionServiceImp] Slf4jLogger.logWarning:12 - No properties path set - looking for transactions.properties in classpath...
2024-10-02 16:50:26 [main] WARN [com.atomikos.icatch.config.UserTransactionServiceImp] Slf4jLogger.logWarning:12 - transactions.properties not found - looking for jta.properties in classpath...
2024-10-02 16:50:26 [main] WARN [com.atomikos.icatch.config.UserTransactionServiceImp] Slf4jLogger.logWarning:12 - Failed to open transactions properties file - using default values
2024-10-02 16:50:26 [main] WARN [com.atomikos.icatch.config.imp.AbstractUserTransactionService] Slf4jLogger.logWarning:12 - /logqm0/myproject could not be created - using default
2024-10-02 16:50:26 [main] WARN [com.atomikos.persistence.Utils] Slf4jLogger.logWarning:12 - /logqm0/myproject could not be created - using default
2024-10-02 16:50:27 [main] INFO [org.springframework.batch.core.repository.support.JobRepositoryFactoryBean] JobRepositoryFactoryBean.afterPropertiesSet:183 - No database type set, using meta data indicating: ORACLE
2024-10-02 16:50:27 [main] INFO [org.springframework.batch.core.launch.support.SimpleJobLauncher] SimpleJobLauncher.afterPropertiesSet:195 - No TaskExecutor has been set, defaulting to synchronous executor.
2024-10-02 16:50:27 [main] INFO [org.apache.commons.vfs2.impl.StandardFileSystemManager] VfsLog.info:136 - Using "/tmp/vfs_cache" as temporary files store.
2024-10-02 16:50:27 [main] INFO [org.springframework.jmx.export.annotation.AnnotationMBeanExporter] MBeanExporter.afterSingletonsInstantiated:431 - Registering beans for JMX exposure on startup
2024-10-02 16:50:27 [main] INFO [org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner] JobLauncherCommandLineRunner.run:118 - Running default command line with: [--logging.level.root=TRACE]
2024-10-02 16:50:27 [main] ERROR [org.springframework.boot.SpringApplication] SpringApplication.reportFailure:839 - Application startup failed
java.lang.StackOverflowError: null
at java.lang.reflect.InvocationTargetException.<init>(InvocationTargetException.java:72)
at sun.reflect.GeneratedMethodAccessor25.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy60.getTransaction(Unknown Source)
at sun.reflect.GeneratedMethodAccessor25.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy60.getTransaction(Unknown Source)
at sun.reflect.GeneratedMethodAccessor25.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy60.getTransaction(Unknown Source)
这是我的 pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<groupId>com.my.project</groupId>
<artifactId>my-project</artifactId>
<version>1.1-SNAPSHOT</version>
<name>My Project</name>
<description>a simple project</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jta-atomikos</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-vfs2</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.54</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.5</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.5</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.15.1</version>
</dependency>
<dependency>
<groupId>com.github.dragon66</groupId>
<artifactId>icafe</artifactId>
<version>1.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/icafe-1.1.jar</systemPath>
</dependency>
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.2.0.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/ojdbc8-19.8.0.0.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.30</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>layout</artifactId>
<version>8.0.2</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-core</artifactId>
<version>8.0.2</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.github.jai-imageio</groupId>
<artifactId>jai-imageio-core</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.7.5</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<scm>
<url>${url.git}</url>
<connection>scm:git:${url.git}</connection>
<developerConnection>scm:git:${url.git}</developerConnection>
<tag>HEAD</tag>
</scm>
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>nexus releases</name>
<url>${url.repository}maven-releases</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>nexus snapshots</name>
<url>${url.repository}maven-snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>
提前感谢您的帮助。
这看起来像是 IntelliJ 中的配置设置问题,而不是它实际打包到 Jar 中的方式。由于您正在使用 Batch,并且看起来无法从此日志中找到用于设置事务管理的属性:
transactions.properties 未找到 - 在类路径中寻找 jta.properties...
由于它找不到这个,我假设它正在设置内存数据存储并填充它,这会在启动时导致堆栈溢出。确保您拥有可以找到的 application.properties 文件,如果依赖于 env,请确保传入 env 变量,以便获取正确的属性文件。可以在这里找到更多信息,了解如何传递参数以将 Spring 从命令行指向您版本的属性文件https://docs.spring.io/spring-boot/docs/1.4.2.RELEASE/reference/htmlsingle/ #boot-features-external-config-application-property-files。如果可以的话,可能也想更新到较新的版本,因为这个版本已经过时了。