Spring StackOverflowError только с jarJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Spring StackOverflowError только с jar

Сообщение Anonymous »

В настоящее время я столкнулся с проблемой в проекте 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.: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.(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

4.0.0

org.springframework.boot
spring-boot-starter-parent
1.4.2.RELEASE

com.my.project
my-project
1.1-SNAPSHOT
My Project
a simple project


1.8
UTF-8
UTF-8



org.springframework.boot
spring-boot-starter-batch



org.springframework.boot
spring-boot-starter-jta-atomikos



org.springframework.boot
spring-boot-starter-test
test



org.hibernate
hibernate-validator



org.apache.commons
commons-lang3
3.5



org.apache.commons
commons-vfs2
2.1



com.jcraft
jsch
0.1.54


org.apache.poi
poi
5.2.5



org.apache.poi
poi-ooxml
5.2.5



commons-io
commons-io
2.15.1



com.github.dragon66
icafe
1.1
system
${project.basedir}/lib/icafe-1.1.jar



com.oracle.jdbc
ojdbc8
12.2.0.1
system
${project.basedir}/lib/ojdbc8-19.8.0.0.jar



org.apache.pdfbox
pdfbox
2.0.30


com.itextpdf
layout
8.0.2


com.itextpdf
itext-core
8.0.2
pom


com.github.jai-imageio
jai-imageio-core
1.3.1


com.itextpdf
itextpdf
5.5.13.1


org.apache.logging.log4j
log4j-api





org.springframework.boot
spring-boot-maven-plugin

true



org.springframework.boot
spring-boot-maven-plugin
2.7.5



repackage








${url.git}
scm:git:${url.git}
scm:git:${url.git}
HEAD




nexus-releases
nexus releases
${url.repository}maven-releases



nexus-snapshots
nexus snapshots
${url.repository}maven-snapshots





Заранее благодарим за помощь.
ИЗМЕНИТЬ
Следующие ваш совет, я сравнил стеки jar и IntelliJ.
Я заметил, что одна строка немного отличается.
На IntelliJ:
2024-10-03 07:22:29 [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=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]] with [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/myproject/configuration/MyProjectTransactionManagerConfiguration.class]]

И с Jar:
2024-10-03 07:25:12 [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/myproject/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]]

Я думаю, что порядок вызовов зависимостей не одинаков, и это единственное различие, которое я заметил.
Вот мои две конфигурации.< /p>
@Configuration
@EnableBatchProcessing
public class BatchConfiguration {

@Autowired
private JobBuilderFactory jobBuilderFactory;

@Autowired
private StepBuilderFactory stepBuilderFactory;

@Autowired
@Qualifier("abcDs")
private DataSource abcDataSource;

@Autowired
@Qualifier("xyzDs")
private DataSource xyzDataSource;

@Autowired
private PlatformTransactionManager customTransactionManager;

@Autowired
private MyProjectConfiguration myProjectConfiguration;

@Autowired
private FileSystemOptions abcFileSystemOptions;

@Autowired
private FileSystemOptions xyzFileSystemOptions;

@Bean
public BatchConfigurer batchConfigurer() {
return new MyProjectBatchConfigurer(xyzDataSource, customTransactionManager);
}

@Bean
public DocumentItemReader documentReader() {
DocumentItemReader documentItemReader = new DocumentItemReader();
documentItemReader.setJdbcTemplate(new JdbcTemplate(abcDataSource));
documentItemReader.setTypeXyzConfigs(myProjectConfiguration.getTypeXyzConfigs());

return documentItemReader;
}

@Bean
public DocumentItemProcessor documentProcessor() {
DocumentItemProcessor documentItemProcessor = new DocumentItemProcessor();
documentItemProcessor.setXyzJdbcTemplate(new JdbcTemplate(xyzDataSource));

return documentItemProcessor;
}

@Bean
public DocumentItemWriter documentWriter() throws FileSystemException {
DocumentItemWriter documentItemWriter = new DocumentItemWriter();
documentItemWriter.setXyzJdbcTemplate(new JdbcTemplate(xyzDataSource));
documentItemWriter.setAbcJdbcTemplate(new JdbcTemplate(abcDataSource));
documentItemWriter.setFileSystemManager(fileSystemManager());
documentItemWriter.setAbcFileSystemOptions(abcFileSystemOptions);
documentItemWriter.setXyzFileSystemOptions(xyzFileSystemOptions);
documentItemWriter.setTempFolder(new File(myProjectConfiguration.getTempFolder()));
documentItemWriter.setMultiFolder(new File(myProjectConfiguration.getMultiFolder()));
documentItemWriter.setAbcFilePathPrefix(myProjectConfiguration.getAbcFilePrefix());
documentItemWriter.setXyzFilePathPrefix(myProjectConfiguration.getXyzFilePrefix());

return documentItemWriter;
}

@Bean
public DocumentSkipListener documentSkipListener() {
DocumentSkipListener documentSkipListener = new DocumentSkipListener();
documentSkipListener.setAbcJdbcTemplate(new JdbcTemplate(abcDataSource));

return documentSkipListener;
}

@Bean
public ReportDocumentSkipListener reportDocumentSkipListener() {
return new ReportDocumentSkipListener(myProjectReportCollection());
}

@Bean
public MyProjectReportCollection myProjectReportCollection() {
return new MyProjectReportCollection();
}

@Bean
public ReportDocumentItemProcessListener reportDocumentItemProcessListener() {
return new ReportDocumentItemProcessListener(myProjectReportCollection());
}

@Bean
public ReportDocumentItemWriteListener reportDocumentItemWriteListener() {
return new ReportDocumentItemWriteListener(myProjectReportCollection());
}

@Bean
public ReportGenerationTasklet reportGenerationTasklet() {
ReportGenerationTasklet reportGenerationTasklet = new ReportGenerationTasklet();
reportGenerationTasklet.setReportFileNamePrefix(myProjectConfiguration.getReportFileNamePrefix());
reportGenerationTasklet.setReportFolder(new File(myProjectConfiguration.getReportPath()));
reportGenerationTasklet.setReports(myProjectReportCollection());

return reportGenerationTasklet;
}

@Bean
public Job myProjectJob(JobCompletionNotificationListener listener) throws FileSystemException {

ReportJobExecutionDecider reportJobExecutionDecider = new ReportJobExecutionDecider(
myProjectConfiguration.isReportEnabled());
Flow reportOptionalFlow = new FlowBuilder("reportFlow").start(reportJobExecutionDecider)
.on(ReportJobExecutionDecider.GENERATE_REPORT_FLOW_STATUS).to(reportGenerationStep())
.from(reportJobExecutionDecider).on("*").end().build();

return jobBuilderFactory.get("myProjectJob").incrementer(new RunIdIncrementer()).listener(listener)
.flow(documentsStep()).next(reportOptionalFlow).end().build();
}

@Bean
public Step documentsStep() throws FileSystemException {
return stepBuilderFactory.get("documentsStep").chunk(1).reader(documentReader())
.processor(documentProcessor()).writer(documentWriter()).listener(reportDocumentItemProcessListener())
.listener(reportDocumentItemWriteListener()).faultTolerant().skipPolicy(new DocumentItemSkipPolicy())
.listener(documentSkipListener()).listener(reportDocumentSkipListener())
.transactionManager(customTransactionManager).build();
}

@Bean
public Step reportGenerationStep() {
return stepBuilderFactory.get("reportGenerationStep").tasklet(reportGenerationTasklet()).build();
}

@Bean
public FileSystemManager fileSystemManager() throws FileSystemException {
return VFS.getManager();
}

}

Примечание: jobBuilderFactory и StepBuilderFactory выделены красным цветом с сообщением «Не удалось выполнить автоматическое подключение. Компоненты данного типа не найдены».
@Configuration
@EnableConfigurationProperties(AtomikosProperties.class)
public class MyProjectTransactionManagerConfiguration {

@Autowired
private JtaProperties jtaProperties;

@Autowired
@Qualifier("abcDs")
private DataSource abcDataSource;

@Autowired
@Qualifier("xyzDs")
private DataSource xyzDataSource;

@Bean(initMethod = "init", destroyMethod = "shutdownForce")
@ConditionalOnMissingBean(UserTransactionService.class)
public UserTransactionServiceImp userTransactionService(AtomikosProperties atomikosProperties) {
Properties properties = new Properties();
if (StringUtils.hasText(this.jtaProperties.getTransactionManagerId())) {
properties.setProperty("com.atomikos.icatch.tm_unique_name", this.jtaProperties.getTransactionManagerId());
}
properties.setProperty("com.atomikos.icatch.log_base_dir", getLogBaseDir());
properties.putAll(atomikosProperties.asProperties());
return new UserTransactionServiceImp(properties);
}

private String getLogBaseDir() {
if (StringUtils.hasLength(this.jtaProperties.getLogDir())) {
return this.jtaProperties.getLogDir();
}
File home = new ApplicationHome().getDir();
return new File(home, "transaction-logs").getAbsolutePath();
}

@Bean(initMethod = "init", destroyMethod = "close")
@ConditionalOnMissingBean
public UserTransactionManager atomikosTransactionManager(UserTransactionService userTransactionService)
throws Exception {
UserTransactionManager manager = new UserTransactionManager();
manager.setStartupTransactionService(false);
manager.setForceShutdown(true);
return manager;
}

@Bean
public JtaTransactionManager transactionManager(UserTransaction userTransaction,
TransactionManager transactionManager) {
JtaTransactionManager jtaTransactionManager = new JtaTransactionManager(userTransaction, transactionManager);
jtaTransactionManager.setAllowCustomIsolationLevels(true);
return jtaTransactionManager;
}

}


Подробнее здесь: https://stackoverflow.com/questions/790 ... y-with-jar
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»