Spring Batch - 批处理在Eclipse中工作但不作为JAR - 没有显式的DEBUG日志

时间:2014-08-08 10:49:36

标签: eclipse spring spring-batch executable-jar spring-boot

我是Spring的新手。我的批处理使用Spring Boot在Eclipse中工作。

        public class Main {
      public static void main(String [] args) {
          System.exit(SpringApplication.exit(SpringApplication.run(BatchConfiguration.class, args)));
      }
    }

以下是Eclipse的日志。

          .   ____          _            __ _ _
     /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
    ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
     \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
      '  |____| .__|_| |_|_| |_\__, | / / / /
     =========|_|==============|___/=/_/_/_/
     :: Spring Boot ::        (v1.1.4.RELEASE)

    2014-08-08 12:01:09.714  INFO 292 --- [           main] f.i.a.fczeuj.springbatch.Main            : Starting Main on W100023928 with PID 292 (started by Me in D:\Eclipse_workspace\SpringBatchJavaConfig)
    2014-08-08 12:01:09.776  INFO 292 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@714ae2c1: startup date [Fri Aug 08 12:01:09 CEST 2014]; root of context hierarchy
    2014-08-08 12:01:10.494  INFO 292 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'org.springframework.boot.autoconfigure.AutoConfigurationPackages': replacing [Generic bean: class [org.springframework.boot.autoconfigure.AutoConfigurationPackages$BasePackages]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.springframework.boot.autoconfigure.AutoConfigurationPackages$BasePackages]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
    2014-08-08 12:01:10.979  WARN 292 --- [           main] o.s.c.a.ConfigurationClassEnhancer       : @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
    2014-08-08 12:01:10.994  WARN 292 --- [           main] o.s.c.a.ConfigurationClassEnhancer       : @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
    2014-08-08 12:01:11.166  INFO 292 --- [           main] o.s.j.d.DriverManagerDataSource          : Loaded JDBC driver: org.postgresql.Driver
    sql=insert into schema_batch_01.table_batch_donnees_massives values (:num_ligne,(((extract('epoch' from statement_timestamp())*1000)::bigint)-1407492071384)/1000,:prenom, :nom, :rue, :ville, :etat)
    2014-08-08 12:01:11.618  INFO 292 --- [           main] o.s.jdbc.datasource.init.ScriptUtils     : Executing SQL script from class path resource [org/springframework/batch/core/schema-postgresql.sql]
    2014-08-08 12:01:11.619  INFO 292 --- [           main] o.s.jdbc.datasource.init.ScriptUtils     : Executed SQL script from class path resource [org/springframework/batch/core/schema-postgresql.sql] in 1 ms.
    2014-08-08 12:01:11.822  INFO 292 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
    2014-08-08 12:01:11.838  INFO 292 --- [           main] o.s.b.a.b.JobLauncherCommandLineRunner   : Running default command line with: []
    2014-08-08 12:01:11.884  INFO 292 --- [           main] o.s.b.c.r.s.JobRepositoryFactoryBean     : No database type set, using meta data indicating: POSTGRES
    2014-08-08 12:01:12.025  INFO 292 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : No TaskExecutor has been set, defaulting to synchronous executor.
    2014-08-08 12:01:12.493  INFO 292 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [SimpleJob: [name=job1]] launched with the following parameters: [{run.id=28}]
    2014-08-08 12:01:12.664  INFO 292 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [taskletTruncate]
    truncateDonnees DataSource=
    org.springframework.jdbc.datasource.DriverManagerDataSource@7e913c56
    Username=
    role_cnx_batch_seminaire_dev
    2014-08-08 12:01:13.102  INFO 292 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [stepInserts]
    2014-08-08 12:01:18.079  INFO 292 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [SimpleJob: [name=job1]] completed with the following parameters: [{run.id=28}] and the following status: [COMPLETED]
    2014-08-08 12:01:18.079  INFO 292 --- [           main] f.i.a.fczeuj.springbatch.Main            : Started Main in 8.677 seconds (JVM running for 9.239)
    2014-08-08 12:01:18.079  INFO 292 --- [           main] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@714ae2c1: startup date [Fri Aug 08 12:01:09 CEST 2014]; root of context hierarchy
    2014-08-08 12:01:18.079  INFO 292 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown

所以我在MANIFEST中构建了一个带有maven依赖项和主类的JAR并运行JAR
java -jar myArchive.jar
但是JAR什么都不做,DOS日志中没有错误。

        2014-08-08 12:10:47.125 DEBUG   --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'batchConfiguration'
    sql=insert into schema_batch_01.table_batch_donnees_massives values (:num_ligne,(((extract('epoch' from statement_timestamp())*1000)::bigint)-1407492647125)/1000,:prenom, :nom
    , :rue, :ville, :etat)
    2014-08-08 12:10:47.141 DEBUG   --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Eagerly caching bean 'writer' to allow for resolving potential circular refere
    nces
    2014-08-08 12:10:47.141 DEBUG   --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Invoking afterPropertiesSet() on bean with name 'writer'
    2014-08-08 12:10:47.141 DEBUG   --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Finished creating instance of bean 'writer'
    2014-08-08 12:10:47.141 DEBUG   --- [           main] s.c.a.AnnotationConfigApplicationContext : Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using defa
    ult [org.springframework.context.support.DefaultLifecycleProcessor@4dc1c92b]
    2014-08-08 12:10:47.141 DEBUG   --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'lifecycleProcessor'
    2014-08-08 12:10:47.141 DEBUG   --- [           main] o.s.c.e.PropertySourcesPropertyResolver  : Searching for key 'spring.liveBeansView.mbeanDomain' in [systemProperties]
    2014-08-08 12:10:47.141 DEBUG   --- [           main] o.s.c.e.PropertySourcesPropertyResolver  : Searching for key 'spring.liveBeansView.mbeanDomain' in [systemEnvironment]
    2014-08-08 12:10:47.141 DEBUG   --- [           main] o.s.c.e.PropertySourcesPropertyResolver  : Searching for key 'spring.liveBeansView.mbeanDomain' in [class path resource [
    spring.batch.context.properties]]
    2014-08-08 12:10:47.141 DEBUG   --- [           main] o.s.c.e.PropertySourcesPropertyResolver  : Could not find key 'spring.liveBeansView.mbeanDomain' in any property source.
    Returning [null]
    2014-08-08 12:10:47.157  INFO   --- [           main] f.i.a.fczeuj.springbatch.Main            : Started Main in 0.952 seconds (JVM running for 1.264)
    2014-08-08 12:10:47.157  INFO   --- [           main] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationCont
    ext@356f144c: startup date [Fri Aug 08 12:10:46 CEST 2014]; root of context hierarchy
    2014-08-08 12:10:47.157 DEBUG   --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'lifecycleProcessor'
    2014-08-08 12:10:47.157 DEBUG   --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Destroying singletons in org.springframework.beans.factory.support.DefaultList
    ableBeanFactory@11e7c5cb: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowi
    redAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,batc
    hConfiguration,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcess
    or.enhancedConfigurationProcessor,org.springframework.batch.core.configuration.annotation.ScopeConfiguration,stepScope,jobScope,org.springframework.batch.core.configuration.an
    notation.SimpleBatchConfiguration,jobRepository,jobLauncher,jobRegistry,jobExplorer,transactionManager,jobBuilders,stepBuilders,fr.insee.architecture.fczeuj.springbatch.Contex
    tWithProperties,dataSource,nbIteration,org.springframework.boot.autoconfigure.AutoConfigurationPackages,taskletTruncate,reader,processor,writer,job,stepInserts]; root of facto
    ry hierarchy
    2014-08-08 12:10:47.157 DEBUG   --- [           main] o.s.b.f.support.DisposableBeanAdapter    : Invoking destroy() on bean with name 'batchConfiguration'
    2014-08-08 12:10:47.157 DEBUG   --- [           main] o.s.b.f.support.DisposableBeanAdapter    : Invoking destroy() on bean with name 'org.springframework.batch.core.configura
    tion.annotation.SimpleBatchConfiguration'
    2014-08-08 12:10:47.157 DEBUG   --- [           main] o.s.b.f.support.DisposableBeanAdapter    : Invoking destroy() on bean with name 'fr.architecture.springbatch
    .ContextWithProperties'
    2014-08-08 12:10:47.157 DEBUG   --- [           main] o.s.b.f.support.DisposableBeanAdapter    : Invoking destroy() on bean with name 'org.springframework.batch.core.configura
    tion.annotation.ScopeConfiguration'

在JAR和Eclipse之间缺少日志就在日志行之后:

        sql=insert into schema_batch_01.table_batch_donnees_massives values (:num_ligne,(((extract('epoch' from statement_timestamp())*1000)::bigint)-1407492647125)/1000,:prenom, :nom
    , :rue, :ville, :etat)

你知道为什么我的JAR在不运行Job的情况下中止了吗?谢谢。

1 个答案:

答案 0 :(得分:0)

你在和maven一起建造吗?如果是这样,使用maven-assembly-plugin不会产生运行批处理作业的jar文件,你需要使用如下的spring-boot-maven-plugin:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>1.1.4.RELEASE</version>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <mainClass>your.MainClass</mainClass>
            </configuration>
        </plugin>
    </plugins>
</build>

然后,您可以使用标准的“mvn clean package”命令来获取包含所有必需依赖项和正确清单文件的可执行jar。