我有一个包含数据和业务层的核心项目。然后,Web应用程序,批处理应用程序等可以引用此项目......
将我的网络应用程序构建为WAR时,一切都按预期工作。但是,当构建一个运行我的批处理进程的Fat Jar时,我得到了这个例外:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/company/core/configuration/EntityManagerFactoryConfiguration.class]: Invocation of init method failed; nested exception is java.util.MissingFormatArgumentException: Format specifier '%s'
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:139) [batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at com.company.batch.application.Application.main(Application.java:25) [batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
Caused by: java.util.MissingFormatArgumentException: Format specifier '%s'
at java.util.Formatter.format(Unknown Source) ~[na:1.8.0_51]
at java.util.Formatter.format(Unknown Source) ~[na:1.8.0_51]
at java.lang.String.format(Unknown Source) ~[na:1.8.0_51]
at org.jboss.logging.Slf4jLocationAwareLogger.doLogf(Slf4jLocationAwareLogger.java:81) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.jboss.logging.Logger.debugf(Logger.java:553) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.hibernate.annotations.common.util.StandardClassLoaderDelegateImpl.classForName(StandardClassLoaderDelegateImpl.java:53) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.hibernate.annotations.common.reflection.java.JavaReflectionManager.packageForName(JavaReflectionManager.java:147) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.packageInfo(AnnotationMetadataProvider.java:128) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.getTypeMetadataFor(AnnotationMetadataProvider.java:111) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.hibernate.search.spi.SearchIntegratorBuilder.initDocumentBuilders(SearchIntegratorBuilder.java:373) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.hibernate.search.spi.SearchIntegratorBuilder.buildNewSearchFactory(SearchIntegratorBuilder.java:199) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.hibernate.search.spi.SearchIntegratorBuilder.buildSearchIntegrator(SearchIntegratorBuilder.java:117) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated(HibernateSearchSessionFactoryObserver.java:66) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:52) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:588) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:150) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:338) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570) ~[batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
... 13 common frames omitted
11:00:11.695 [Resource Destroyer in BasicResourcePool.close()] DEBUG c.m.v2.c3p0.impl.NewPooledConnection - com.mchange.v2.c3p0.impl.NewPooledConnection@2cb9d186 closed by a client.
Exception in thread "main" java.lang.Exception: DEBUG -- CLOSE BY CLIENT STACK TRACE
at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:646) [batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at com.mchange.v2.c3p0.impl.NewPooledConnection.closeMaybeCheckedOut(NewPooledConnection.java:259) [batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:619) [batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/company/core/configuration/EntityManagerFactoryConfiguration.class]: Invocation of init method
at com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:1024) [batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
failed; nested exception is java.util.MissingFormatArgumentException: Format specifier '%s'
at com.mchange.v2.resourcepool.BasicResourcePool.destroyResource(BasicResourcePool.java:1049) [batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at com.mchange.v2.resourcepool.BasicResourcePool.destroyResource(BasicResourcePool.java:1010) [batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
at com.mchange.v2.resourcepool.BasicResourcePool.access$100(BasicResourcePool.java:44) [batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) at com.mchange.v2.resourcepool.BasicResourcePool$5.run(BasicResourcePool.java:1260) [batch-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)11:00:11.703 [Resource Destroyer in BasicResourcePool.close()] DEBUG c.m.v.c.i.C3P0PooledConnecti
onPool - Successfully destroyed PooledConnection: com.mchange.v2.c3p0.impl.NewPooledConnection@2cb9d186
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
11:00:11.704 [Resource Destroyer in BasicResourcePool.close()] DEBUG c.m.v.resourcepool.BasicResourcePool - Successfully destroyed resource: com.mchange.v2.c3p0.impl.NewPooledConnection@2cb9d186
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:139)
at com.company.batch.application.Application.main(Application.java:25)
Caused by: java.util.MissingFormatArgumentException: Format specifier '%s'
at java.util.Formatter.format(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.lang.String.format(Unknown Source)
at org.jboss.logging.Slf4jLocationAwareLogger.doLogf(Slf4jLocationAwareLogger.java:81)
at org.jboss.logging.Logger.debugf(Logger.java:553)
at org.hibernate.annotations.common.util.StandardClassLoaderDelegateImpl.classForName(StandardClassLoaderDelegateImpl.java:53)
at org.hibernate.annotations.common.reflection.java.JavaReflectionManager.packageForName(JavaReflectionManager.java:147)
at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.packageInfo(AnnotationMetadataProvider.java:128)
at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.getTypeMetadataFor(AnnotationMetadataProvider.java:111)
at org.hibernate.search.spi.SearchIntegratorBuilder.initDocumentBuilders(SearchIntegratorBuilder.java:373)
at org.hibernate.search.spi.SearchIntegratorBuilder.buildNewSearchFactory(SearchIntegratorBuilder.java:199)
at org.hibernate.search.spi.SearchIntegratorBuilder.buildSearchIntegrator(SearchIntegratorBuilder.java:117)
at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated(HibernateSearchSessionFactoryObserver.java:66)
at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:52)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:588)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:150)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:338)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
... 13 more
我找到了这个:https://stackoverflow.com/a/20799179/2767835
我认为在构建Fat Jar时我会遇到冲突的包,但我无法弄清楚什么是冲突的。
这是我的依赖树:
--- maven-dependency-plugin:2.1:tree (default-cli) @ batch ---
com.company:batch:jar:1.0-SNAPSHOT
+- com.company:core:jar:1.0-SNAPSHOT:compile
| +- org.springframework:spring-web:jar:4.1.6.RELEASE:compile
| | +- org.springframework:spring-aop:jar:4.1.6.RELEASE:compile
| | \- org.springframework:spring-beans:jar:4.1.6.RELEASE:compile
| +- org.springframework.security:spring-security-core:jar:4.0.1.RELEASE:compile
| | +- aopalliance:aopalliance:jar:1.0:compile
| | \- org.springframework:spring-expression:jar:4.1.6.RELEASE:compile
| +- org.springframework.security:spring-security-web:jar:4.0.1.RELEASE:compile
| +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
| +- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
| +- org.hibernate:hibernate-c3p0:jar:4.3.8.Final:compile
| | +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
| | +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
| | +- org.hibernate:hibernate-core:jar:4.3.8.Final:compile
| | | +- antlr:antlr:jar:2.7.7:compile
| | | \- org.jboss:jandex:jar:1.1.0.Final:compile
| | \- com.mchange:c3p0:jar:0.9.2.1:compile
| | \- com.mchange:mchange-commons-java:jar:0.2.3.4:compile
| +- org.hibernate:hibernate-entitymanager:jar:4.3.0.Final:compile
| | +- dom4j:dom4j:jar:1.6.1:compile
| | | \- xml-apis:xml-apis:jar:1.0.b2:compile
| | +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.4.Final:compile
| | +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
| | +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.0.Final:compile
| | \- org.javassist:javassist:jar:3.18.1-GA:compile
| +- org.hibernate:hibernate-search-orm:jar:5.2.0.Final:compile
| | \- org.hibernate:hibernate-search-engine:jar:5.2.0.Final:compile
| | +- org.apache.lucene:lucene-core:jar:4.10.4:compile
| | +- org.apache.lucene:lucene-analyzers-common:jar:4.10.4:compile
| | \- org.apache.lucene:lucene-facet:jar:4.10.4:compile
| | \- org.apache.lucene:lucene-queries:jar:4.10.4:compile
| +- org.hibernate:hibernate-search-infinispan:jar:5.2.0.Final:compile
| | \- org.infinispan:infinispan-lucene-directory:jar:7.2.0.Final:compile
| | \- org.infinispan:infinispan-core:jar:7.2.0.Final:compile
| | +- org.infinispan:infinispan-commons:jar:7.2.0.Final:compile
| | +- org.jgroups:jgroups:jar:3.6.2.Final:compile
| | +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.1.Final:compile
| | \- org.jboss.marshalling:jboss-marshalling-osgi:jar:1.4.10.Final:compile
| +- org.springframework.data:spring-data-jpa:jar:1.7.2.RELEASE:compile
| | +- org.springframework.data:spring-data-commons:jar:1.9.2.RELEASE:compile
| | +- org.springframework:spring-orm:jar:4.0.9.RELEASE:compile
| | +- org.springframework:spring-tx:jar:4.0.9.RELEASE:compile
| | \- org.aspectj:aspectjrt:jar:1.8.4:compile
| +- mysql:mysql-connector-java:jar:5.1.15:compile
| +- com.datastax.cassandra:cassandra-driver-core:jar:2.1.3:compile
| | +- io.netty:netty:jar:3.9.0.Final:compile
| | +- com.google.guava:guava:jar:14.0.1:compile
| | \- com.codahale.metrics:metrics-core:jar:3.0.2:compile
| +- com.datastax.cassandra:cassandra-driver-mapping:jar:2.1.2:compile
| +- org.springframework:spring-context-support:jar:4.1.6.RELEASE:compile
| +- commons-codec:commons-codec:jar:1.10:compile
| +- org.springframework:spring-context:jar:4.1.6.RELEASE:compile
| +- org.modelmapper:modelmapper:jar:0.7.3:compile
| +- javax.servlet:javax.servlet-api:jar:3.1.0:compile
| +- javax.inject:javax.inject:jar:1:compile
| +- com.rabbitmq:amqp-client:jar:3.5.1:compile
| +- javax.mail:mail:jar:1.4.7:compile
| | \- javax.activation:activation:jar:1.1:compile
| +- org.aspectj:aspectjweaver:jar:1.8.5:compile
| +- org.apache.commons:commons-lang3:jar:3.4:compile
| +- net.sf.ehcache:ehcache:jar:2.9.0:compile
| +- com.fasterxml.jackson.core:jackson-databind:jar:2.2.3:compile
| | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.2.3:compile
| | \- com.fasterxml.jackson.core:jackson-core:jar:2.2.3:compile
| +- commons-io:commons-io:jar:2.4:compile
| +- org.apache.axis:axis:jar:1.4:compile
| +- javax.xml:jaxrpc-api:jar:1.1:compile
| +- commons-discovery:commons-discovery:jar:0.2:compile
| | \- commons-logging:commons-logging:jar:1.0.3:compile
| +- wsdl4j:wsdl4j:jar:1.5.1:compile
| \- com.github.springtestdbunit:spring-test-dbunit:jar:1.2.1:compile
+- com.company:company-dto:jar:1.0-SNAPSHOT:compile
+- com.company:company-shared:jar:1.0-SNAPSHOT:compile
| +- commons-validator:commons-validator:jar:1.4.1:compile
| | +- commons-beanutils:commons-beanutils:jar:1.8.3:compile
| | +- commons-digester:commons-digester:jar:1.8.1:compile
| | \- commons-collections:commons-collections:jar:3.2.1:compile
| +- com.googlecode.libphonenumber:libphonenumber:jar:7.0.6:compile
| +- com.neovisionaries:nv-i18n:jar:1.15:compile
| \- org.apache.commons:commons-exec:jar:1.3:compile
+- org.springframework.boot:spring-boot-starter-batch:jar:1.2.3.RELEASE:compile
| +- org.springframework.boot:spring-boot-starter:jar:1.2.3.RELEASE:compile
| | +- org.springframework.boot:spring-boot:jar:1.2.3.RELEASE:compile
| | +- org.springframework.boot:spring-boot-autoconfigure:jar:1.2.3.RELEASE:compile
| | | \- org.yaml:snakeyaml:jar:1.14:compile
| | \- org.springframework.boot:spring-boot-starter-logging:jar:1.2.3.RELEASE:compile
| | +- org.slf4j:jcl-over-slf4j:jar:1.7.10:compile
| | +- org.slf4j:jul-to-slf4j:jar:1.7.11:compile
| | +- org.slf4j:log4j-over-slf4j:jar:1.7.11:compile
| | \- ch.qos.logback:logback-classic:jar:1.1.3:compile
| | \- ch.qos.logback:logback-core:jar:1.1.3:compile
| +- org.hsqldb:hsqldb:jar:2.3.2:compile
| +- org.springframework:spring-core:jar:4.1.6.RELEASE:compile
| +- org.springframework:spring-jdbc:jar:4.1.6.RELEASE:compile
| \- org.springframework.batch:spring-batch-core:jar:3.0.3.RELEASE:compile
| +- com.ibm.jbatch:com.ibm.jbatch-tck-spi:jar:1.0:compile
| | \- javax.batch:javax.batch-api:jar:1.0:compile
| +- com.thoughtworks.xstream:xstream:jar:1.4.7:compile
| | +- xmlpull:xmlpull:jar:1.1.3.1:compile
| | \- xpp3:xpp3_min:jar:1.1.4c:compile
| +- org.codehaus.jettison:jettison:jar:1.2:compile
| \- org.springframework.batch:spring-batch-infrastructure:jar:3.0.3.RELEASE:compile
| \- org.springframework.retry:spring-retry:jar:1.1.0.RELEASE:compile
+- org.springframework.boot:spring-boot-dependencies:pom:1.2.3.RELEASE:compile
\- org.quartz-scheduler:quartz:jar:2.2.1:compile
+- c3p0:c3p0:jar:0.9.1.1:compile
\- org.slf4j:slf4j-api:jar:1.6.6:compile
和pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>com.company</groupId>
<artifactId>batch</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<java-version>1.8</java-version>
<spring-boot-version>1.2.3.RELEASE</spring-boot-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.company</groupId>
<artifactId>core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.company</groupId>
<artifactId>company-dto</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.company</groupId>
<artifactId>company-shared</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
<version>${spring-boot-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot-version}</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot-version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.company.batch.application.Application</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
评论中要求的代码:
@SpringBootApplication
@ComponentScan({"com.company.batch", "com.company.core", "com.company.shared"})
@EnableAutoConfiguration
public class Application implements CommandLineRunner {
public static void main(String[] args) {
ConfigurableApplicationContext ctx = new SpringApplicationBuilder(Application.class)
.web(false)
.run(args);
}
@Autowired
private IConsumerFactory consumerFactory;
@Autowired
private ApplicationContext applicationContext;
@Override
public void run(String... strings) throws Exception {
String processType = strings[0];
String processName = strings[1];
if(processType != null && !processType.isEmpty() && processName != null && !processName.isEmpty()) {
if (processType.toLowerCase().equals("-c") || processType.toLowerCase().equals("-consumer")) {
IConsumer consumer = consumerFactory.getConsumerByQueueName(processName);
consumer.start();
} else if (processType.toLowerCase().equals("-st") || processType.toLowerCase().equals("-scheduledtask")) {
Scheduler scheduler = (Scheduler)applicationContext.getBean(processName);
scheduler.start();
}
}
}
}
更新
我已将其缩小到这两个包或这些包使用的代码。它删除了与搜索有关的所有内容后,它可以工作。
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-orm</artifactId>
<version>5.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-infinispan</artifactId>
<version>5.2.0.Final</version>
</dependency>
在启动entityManagerFactory期间的某个时刻,创建了一个搜索索引。
然而,为什么在运行胖罐时失败而不是在tomcat上运行战争时我不知道。此外,一切都在调试中使用,包括搜索。