Spring 引导不扫描主包的子包
Spring boot not scanning sub-sub-packages of main package
我有理由相信 Spring Boot 至少不会扫描一个实体 class,尽管该实体位于主包的子包中。我已经让它与 @ComponentScan 注释一起工作,至少在某种程度上是这样。但是,我注意到另一个组件也不是 运行。我确信这非常简单,因为这是来自不同包的非常接近的副本。
注意:我尝试添加@ComponentScan、@EntityScan、@EnableJpaRepositories。这已经摆脱了原来的错误,但它没有选择@Service GenerateFileService(如下所示),所以我将相应的包添加到所有注释中。我原以为@SpringBootApplication 会自动找到所有相关的 Spring bean,前提是所有 classes 都在应用程序的子包下,但事实并非如此。
堆栈跟踪是:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-04-19 06:28:48 ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'generateFileService' defined in file [C:\projects-new\cirrus-bluecost-ssc-file-generator\target\classes\com\mycomp\cloud\cost\ssc\file\generator\application\GenerateFileService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'costDataRepository' defined in com.mycomp.cloud.cost.ssc.file.generator.domain.model.CostDataRepository defined in @EnableJpaRepositories declared on BlueCostSSCFileGeneratorApplication: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.mycomp.cloud.cost.ssc.file.generator.domain.model.CostData
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:228)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1358)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1204)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean[=11=](AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:895)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at com.mycomp.cloud.cost.ssc.file.generator.BlueCostSSCFileGeneratorApplication.main(BlueCostSSCFileGeneratorApplication.java:26)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'costDataRepository' defined in com.mycomp.cloud.cost.ssc.file.generator.domain.model.CostDataRepository defined in @EnableJpaRepositories declared on BlueCostSSCFileGeneratorApplication: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.mycomp.cloud.cost.ssc.file.generator.domain.model.CostData
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean[=11=](AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1306)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1226)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:885)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:789)
... 19 common frames omitted
Caused by: java.lang.IllegalArgumentException: Not a managed type: class com.mycomp.cloud.cost.ssc.file.generator.domain.model.CostData
at org.hibernate.metamodel.internal.MetamodelImpl.managedType(MetamodelImpl.java:582)
at org.hibernate.metamodel.internal.MetamodelImpl.managedType(MetamodelImpl.java:85)
at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.<init>(JpaMetamodelEntityInformation.java:75)
at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:66)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:229)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:179)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:162)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:72)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:309)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet(RepositoryFactoryBeanSupport.java:297)
at org.springframework.data.util.Lazy.getNullable(Lazy.java:212)
at org.springframework.data.util.Lazy.get(Lazy.java:94)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:300)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:144)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)
... 30 common frames omitted
主要应用:
package com.mycompany.cloud.cost.ssc.file.generator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@SpringBootApplication(scanBasePackages = "com.ibm.cio.cloud.cost.ssc.file.generator")
@ComponentScan({"com.ibm.cio.cloud.cost.ssc.file.generator.domain.model","com.ibm.cio.cloud.cost.ssc.file.generator.application","com.ibm.cio.cloud.cost.ssc.file.generator.infrastructure.persistence","com.ibm.cio.cloud.cost.ssc.file.generator.infrastructure.persistence.file.system","com.ibm.cio.cloud.cost.ssc.file.generator.configuration"}) /* ,"com.ibm.cio.cloud.cost.ssc.file.generator.domain.model.CostData" */
@EntityScan({"com.ibm.cio.cloud.cost.ssc.file.generator.domain.model","com.ibm.cio.cloud.cost.ssc.file.generator.application","com.ibm.cio.cloud.cost.ssc.file.generator.infrastructure.persistence","com.ibm.cio.cloud.cost.ssc.file.generator.infrastructure.persistence.file.system","com.ibm.cio.cloud.cost.ssc.file.generator.configuration"}) /* ,"com.ibm.cio.cloud.cost.ssc.file.generator.domain.model.CostData" */
@EnableTransactionManagement
@EnableAutoConfiguration
@EnableJpaRepositories(basePackages = {"com.ibm.cio.cloud.cost.ssc.file.generator.domain.model","com.ibm.cio.cloud.cost.ssc.file.generator.application","com.ibm.cio.cloud.cost.ssc.file.generator.infrastructure.persistence","com.ibm.cio.cloud.cost.ssc.file.generator.einfrastructure.persistence.file.system","com.ibm.cio.cloud.cost.ssc.file.generator.configuration"},
basePackageClasses = com.ibm.cio.cloud.cost.ssc.file.generator.domain.model.CostDataRepository.class)
public class BlueCostSSCFileGeneratorApplication {
public static void main(String[] args) {
SpringApplication.run(BlueCostSSCFileGeneratorApplication.class, args);
}
}
生成文件服务:
package com.mycomp.cloud.cost.ssc.file.generator.application;
import java.util.List;
import com.mycomp.cloud.cost.ssc.file.generator.application.util.LogLayer;
import com.mycomp.cloud.cost.ssc.file.generator.application.util.LogType;
import com.mycomp.cloud.cost.ssc.file.generator.application.util.LogUtils;
import com.mycomp.cloud.cost.ssc.file.generator.configuration.FileGeneratorProperties;
import com.mycomp.cloud.cost.ssc.file.generator.domain.model.CostData;
import com.mycomp.cloud.cost.ssc.file.generator.domain.model.CostDataRepository;
import com.mycomp.cloud.cost.ssc.file.generator.domain.model.SSCFileDescriptor;
import com.mycomp.cloud.cost.ssc.file.generator.domain.model.csv.CsvFileGenerator;
import com.mycomp.cloud.cost.ssc.file.generator.domain.model.ebcdic.EBCDICFileGenerator;
import com.mycomp.cloud.cost.ssc.file.generator.infrastructure.persistence.file.system.FileWriter;
import com.mycomp.cloud.cost.ssc.file.generator.infrastructure.port.email.EmailService;
import com.mycomp.cloud.cost.ssc.file.generator.process.model.LastRunResult;
import com.mycomp.cloud.cost.ssc.file.generator.process.model.RunResult;
import com.mycomp.cloud.cost.ssc.file.generator.process.model.RunResultService;
import org.slf4j.Logger;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class GenerateFileService {
@Autowired
private final CostDataRepository costDataRepository;
private FileWriter fileWriter;
private final FileGeneratorProperties properties;
private static final String CREATE_FILES = "CREATE_FILES";
private Logger logger;
private final ObjectFactory<SSCFileDescriptor> fileDescriptorFactory;
private BeanFactory beanFactory;
private RunResultService runResultService;
private EmailService emailService;
public GenerateFileService(CostDataRepository costDataRepository, FileWriter fileWriter, FileGeneratorProperties properties,
ObjectFactory<SSCFileDescriptor> fileDescriptorFactory,
BeanFactory beanFactory, RunResultService runResultService,
EmailService emailService) {
this.costDataRepository = costDataRepository;
this.fileWriter = fileWriter;
this.properties = properties;
this.fileDescriptorFactory = fileDescriptorFactory;
this.beanFactory = beanFactory;
this.runResultService = runResultService;
this.emailService = emailService;
}
@Autowired
public void setLogger(Logger logger) {
this.logger = logger;
}
@Transactional
public FileGenerationResult createFiles() {
/* Code omitted */
return result;
}
}
成本数据实体
package com.mycomp.cloud.cost.ssc.file.generator.domain.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.math.BigDecimal;
@Entity
public class CostData {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private Long costDataId;
@Column(name = "COSTINGAMOUNT")
private BigDecimal totalChargesAmount;
public Long getCostDataId() {
return costDataId;
}
}
CostDataRepository.java
package com.mycomp.cloud.cost.ssc.file.generator.domain.model;
import java.util.List;
import org.springframework.data.repository.CrudRepository;
public interface CostDataRepository extends CrudRepository<CostData, Long> {
List<CostData> findByCostDataIdGreaterThanOrderByCostDataIdAsc(Long lastId);
}
根据错误日志,您正在定义管理实体 com.mycomp.cloud.cost.ssc.file.generator.domain.model.CostData
的存储库 CostDataRepository,但包 com.mycomp.cloud.cost.ssc.file.generator.domain
没有出现在您正在配置的 @EntityScan
中。
另外 @ComponentScan
用于组件而非实体,因此您应该删除此行。
这项工作是现有项目的副本,但我需要重构它以部署到云平台。我希望得到指导,说您缺少 @SpringFinder 注释,或类似的东西,或者以某种方式缺少一个注释。相反,我放弃了尝试并重新开始。可用的版本只有 @SpringBootApplication,但我不知道它不喜欢什么。开始一个新项目很有帮助。
我有理由相信 Spring Boot 至少不会扫描一个实体 class,尽管该实体位于主包的子包中。我已经让它与 @ComponentScan 注释一起工作,至少在某种程度上是这样。但是,我注意到另一个组件也不是 运行。我确信这非常简单,因为这是来自不同包的非常接近的副本。
注意:我尝试添加@ComponentScan、@EntityScan、@EnableJpaRepositories。这已经摆脱了原来的错误,但它没有选择@Service GenerateFileService(如下所示),所以我将相应的包添加到所有注释中。我原以为@SpringBootApplication 会自动找到所有相关的 Spring bean,前提是所有 classes 都在应用程序的子包下,但事实并非如此。
堆栈跟踪是:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-04-19 06:28:48 ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'generateFileService' defined in file [C:\projects-new\cirrus-bluecost-ssc-file-generator\target\classes\com\mycomp\cloud\cost\ssc\file\generator\application\GenerateFileService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'costDataRepository' defined in com.mycomp.cloud.cost.ssc.file.generator.domain.model.CostDataRepository defined in @EnableJpaRepositories declared on BlueCostSSCFileGeneratorApplication: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.mycomp.cloud.cost.ssc.file.generator.domain.model.CostData
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:228)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1358)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1204)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean[=11=](AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:895)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at com.mycomp.cloud.cost.ssc.file.generator.BlueCostSSCFileGeneratorApplication.main(BlueCostSSCFileGeneratorApplication.java:26)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'costDataRepository' defined in com.mycomp.cloud.cost.ssc.file.generator.domain.model.CostDataRepository defined in @EnableJpaRepositories declared on BlueCostSSCFileGeneratorApplication: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.mycomp.cloud.cost.ssc.file.generator.domain.model.CostData
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean[=11=](AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1306)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1226)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:885)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:789)
... 19 common frames omitted
Caused by: java.lang.IllegalArgumentException: Not a managed type: class com.mycomp.cloud.cost.ssc.file.generator.domain.model.CostData
at org.hibernate.metamodel.internal.MetamodelImpl.managedType(MetamodelImpl.java:582)
at org.hibernate.metamodel.internal.MetamodelImpl.managedType(MetamodelImpl.java:85)
at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.<init>(JpaMetamodelEntityInformation.java:75)
at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:66)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:229)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:179)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:162)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:72)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:309)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet(RepositoryFactoryBeanSupport.java:297)
at org.springframework.data.util.Lazy.getNullable(Lazy.java:212)
at org.springframework.data.util.Lazy.get(Lazy.java:94)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:300)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:144)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)
... 30 common frames omitted
主要应用:
package com.mycompany.cloud.cost.ssc.file.generator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@SpringBootApplication(scanBasePackages = "com.ibm.cio.cloud.cost.ssc.file.generator")
@ComponentScan({"com.ibm.cio.cloud.cost.ssc.file.generator.domain.model","com.ibm.cio.cloud.cost.ssc.file.generator.application","com.ibm.cio.cloud.cost.ssc.file.generator.infrastructure.persistence","com.ibm.cio.cloud.cost.ssc.file.generator.infrastructure.persistence.file.system","com.ibm.cio.cloud.cost.ssc.file.generator.configuration"}) /* ,"com.ibm.cio.cloud.cost.ssc.file.generator.domain.model.CostData" */
@EntityScan({"com.ibm.cio.cloud.cost.ssc.file.generator.domain.model","com.ibm.cio.cloud.cost.ssc.file.generator.application","com.ibm.cio.cloud.cost.ssc.file.generator.infrastructure.persistence","com.ibm.cio.cloud.cost.ssc.file.generator.infrastructure.persistence.file.system","com.ibm.cio.cloud.cost.ssc.file.generator.configuration"}) /* ,"com.ibm.cio.cloud.cost.ssc.file.generator.domain.model.CostData" */
@EnableTransactionManagement
@EnableAutoConfiguration
@EnableJpaRepositories(basePackages = {"com.ibm.cio.cloud.cost.ssc.file.generator.domain.model","com.ibm.cio.cloud.cost.ssc.file.generator.application","com.ibm.cio.cloud.cost.ssc.file.generator.infrastructure.persistence","com.ibm.cio.cloud.cost.ssc.file.generator.einfrastructure.persistence.file.system","com.ibm.cio.cloud.cost.ssc.file.generator.configuration"},
basePackageClasses = com.ibm.cio.cloud.cost.ssc.file.generator.domain.model.CostDataRepository.class)
public class BlueCostSSCFileGeneratorApplication {
public static void main(String[] args) {
SpringApplication.run(BlueCostSSCFileGeneratorApplication.class, args);
}
}
生成文件服务:
package com.mycomp.cloud.cost.ssc.file.generator.application;
import java.util.List;
import com.mycomp.cloud.cost.ssc.file.generator.application.util.LogLayer;
import com.mycomp.cloud.cost.ssc.file.generator.application.util.LogType;
import com.mycomp.cloud.cost.ssc.file.generator.application.util.LogUtils;
import com.mycomp.cloud.cost.ssc.file.generator.configuration.FileGeneratorProperties;
import com.mycomp.cloud.cost.ssc.file.generator.domain.model.CostData;
import com.mycomp.cloud.cost.ssc.file.generator.domain.model.CostDataRepository;
import com.mycomp.cloud.cost.ssc.file.generator.domain.model.SSCFileDescriptor;
import com.mycomp.cloud.cost.ssc.file.generator.domain.model.csv.CsvFileGenerator;
import com.mycomp.cloud.cost.ssc.file.generator.domain.model.ebcdic.EBCDICFileGenerator;
import com.mycomp.cloud.cost.ssc.file.generator.infrastructure.persistence.file.system.FileWriter;
import com.mycomp.cloud.cost.ssc.file.generator.infrastructure.port.email.EmailService;
import com.mycomp.cloud.cost.ssc.file.generator.process.model.LastRunResult;
import com.mycomp.cloud.cost.ssc.file.generator.process.model.RunResult;
import com.mycomp.cloud.cost.ssc.file.generator.process.model.RunResultService;
import org.slf4j.Logger;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class GenerateFileService {
@Autowired
private final CostDataRepository costDataRepository;
private FileWriter fileWriter;
private final FileGeneratorProperties properties;
private static final String CREATE_FILES = "CREATE_FILES";
private Logger logger;
private final ObjectFactory<SSCFileDescriptor> fileDescriptorFactory;
private BeanFactory beanFactory;
private RunResultService runResultService;
private EmailService emailService;
public GenerateFileService(CostDataRepository costDataRepository, FileWriter fileWriter, FileGeneratorProperties properties,
ObjectFactory<SSCFileDescriptor> fileDescriptorFactory,
BeanFactory beanFactory, RunResultService runResultService,
EmailService emailService) {
this.costDataRepository = costDataRepository;
this.fileWriter = fileWriter;
this.properties = properties;
this.fileDescriptorFactory = fileDescriptorFactory;
this.beanFactory = beanFactory;
this.runResultService = runResultService;
this.emailService = emailService;
}
@Autowired
public void setLogger(Logger logger) {
this.logger = logger;
}
@Transactional
public FileGenerationResult createFiles() {
/* Code omitted */
return result;
}
}
成本数据实体
package com.mycomp.cloud.cost.ssc.file.generator.domain.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.math.BigDecimal;
@Entity
public class CostData {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private Long costDataId;
@Column(name = "COSTINGAMOUNT")
private BigDecimal totalChargesAmount;
public Long getCostDataId() {
return costDataId;
}
}
CostDataRepository.java
package com.mycomp.cloud.cost.ssc.file.generator.domain.model;
import java.util.List;
import org.springframework.data.repository.CrudRepository;
public interface CostDataRepository extends CrudRepository<CostData, Long> {
List<CostData> findByCostDataIdGreaterThanOrderByCostDataIdAsc(Long lastId);
}
根据错误日志,您正在定义管理实体 com.mycomp.cloud.cost.ssc.file.generator.domain.model.CostData
的存储库 CostDataRepository,但包 com.mycomp.cloud.cost.ssc.file.generator.domain
没有出现在您正在配置的 @EntityScan
中。
另外 @ComponentScan
用于组件而非实体,因此您应该删除此行。
这项工作是现有项目的副本,但我需要重构它以部署到云平台。我希望得到指导,说您缺少 @SpringFinder 注释,或类似的东西,或者以某种方式缺少一个注释。相反,我放弃了尝试并重新开始。可用的版本只有 @SpringBootApplication,但我不知道它不喜欢什么。开始一个新项目很有帮助。