如何解决使用名称 'dataFlowController' 创建错误 bean 的问题

huangapple 未分类评论55阅读模式
英文:

How to resolve error creating error bean with name 'dataFlowController'

问题

抱歉,由于内容较多,我将无法完整翻译整个代码段。但是,我可以看出您遇到了Spring框架的依赖注入和bean创建相关的问题。您的错误消息表明在创建bean时出现了依赖项不满足的情况。

主要问题似乎出现在以下部分:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'pamdaImportDirect': Unsatisfied
dependency expressed through field 'catalogueImportDirectStarter';
nested exception is
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean
named 'catalogueImportDirectStarter' is expected to be of type
'com.orange.pamda.worker.starter.CatalogueImportDirectStarter' but was
actually of type 'com.sun.proxy.$Proxy129'

这个错误表明在 pamdaImportDirect bean 中的 catalogueImportDirectStarter 字段的类型不正确。根据错误信息,期望的类型是 CatalogueImportDirectStarter,但实际类型是代理类型($Proxy129)。这通常发生在Spring的AOP(面向切面编程)中。

您可能需要检查以下几点来解决这个问题:

  1. 导入包:确保所有涉及的类和接口都正确导入并在类路径中。

  2. 注解标记:确保您正确地使用了Spring的注解(例如 @Autowired)来进行依赖注入。

  3. 配置文件:检查您的配置文件(如XML配置文件或Java配置类)是否正确配置了bean。

  4. 接口/类声明:确保 CatalogueImportDirectStarter 类正确地实现了所需的接口(如果有的话)。

  5. AOP代理:如果在类中使用了Spring的AOP特性,可能会导致代理问题。您可以尝试调整代理设置,或者确保被代理的类是正确的类型。

  6. 循环依赖:检查是否存在循环依赖,这也可能导致依赖注入问题。

  7. Bean命名:检查bean的命名是否与注入点的期望名称匹配。

  8. 使用 @Qualifier 注解:如果有多个候选bean可以注入,可以尝试使用 @Qualifier 注解来明确指定使用哪个bean。

由于限制了单次回答的字数,我无法详细分析您的代码,但以上是一些可能导致您遇到的问题的一般性建议。您可以根据这些方向来检查和排除问题,或者提供更具体的问题细节以获取更准确的帮助。

英文:

hello I am developing a rest service and when I run my application I get the following error:

> > org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataFlowController': Unsatisfied
> dependency expressed through field 'pamdaImportDirectStarter'; nested
> exception is
> org.springframework.beans.factory.UnsatisfiedDependencyException:
> Error creating bean with name 'pamdaImportDirect': Unsatisfied
> dependency expressed through field 'catalogueImportDirectStarter';
> nested exception is
> org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean
> named 'catalogueImportDirectStarter' is expected to be of type
> 'com.orange.pamda.worker.starter.CatalogueImportDirectStarter' but was
> actually of type 'com.sun.proxy.$Proxy129' Apr 08, 2020 12:58:35 PM
> org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
> destroy INFO: Closing JPA EntityManagerFactory for persistence unit
> 'pamdaPersistenceUnit' Apr 08, 2020 12:58:35 PM
> org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
> shutdown INFO: Shutting down ExecutorService Apr 08, 2020 12:58:35 PM
> org.springframework.web.context.ContextLoader
> initWebApplicationContext SEVERE: Context initialization failed
> org.springframework.beans.factory.UnsatisfiedDependencyException:
> Error creating bean with name 'dataFlowController': Unsatisfied
> dependency expressed through field 'pamdaImportDirectStarter'; nested
> exception is
> org.springframework.beans.factory.UnsatisfiedDependencyException:
> Error creating bean with name 'pamdaImportDirect': Unsatisfied
> dependency expressed through field 'catalogueImportDirectStarter';
> nested exception is
> org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean
> named 'catalogueImportDirectStarter' is expected to be of type
> 'com.orange.pamda.worker.starter.CatalogueImportDirectStarter' but was
> actually of type 'com.sun.proxy.$Proxy129' at
> org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
> at
> org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
> at
> org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
> at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
> at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
> at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
> at
> org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
> at
> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
> at
> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
> at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
> at
> org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
> at
> org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
> at
> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
> at
> org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)
> at
> org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)
> at
> org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
> at
> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4685)
> at
> org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5146)
> at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
> at
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
> at
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
> at java.util.concurrent.FutureTask.run(FutureTask.java:266) at
> org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
> at
> java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
> at
> org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
> at
> org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841)
> at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
> at
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
> at
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
> at java.util.concurrent.FutureTask.run(FutureTask.java:266) at
> org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
> at
> java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
> at
> org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
> at
> org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
> at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
> at
> org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
> at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
> at
> org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
> at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
> at org.apache.catalina.startup.Catalina.start(Catalina.java:633) at
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:498) at
> org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:343) at
> org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:474) Caused
> by: org.springframework.beans.factory.UnsatisfiedDependencyException:
> Error creating bean with name 'pamdaImportDirect': Unsatisfied
> dependency expressed through field 'catalogueImportDirectStarter';
> nested exception is
> org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean
> named 'catalogueImportDirectStarter' is expected to be of type
> 'com.orange.pamda.worker.starter.CatalogueImportDirectStarter' but was
> actually of type 'com.sun.proxy.$Proxy129' at
> org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
> at
> org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)

here is the code for my rest service "dataFlowController" :

 package com.orange.pamda.controller;

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.orange.pamda.config.PamdaServerProperty;
import com.orange.pamda.dao.ProfileDao;
import com.orange.pamda.dao.ScopeDao;
import com.orange.pamda.interfaces.v11.CatalogueSystem;
import com.orange.pamda.worker.service.WorkerService;
import com.orange.pamda.worker.starter.CatalogueImportDirectStarter;
import com.orange.pamda.worker.starter.MappingExportStarter;
import com.orange.pamda.worker.starter.MappingImportStarter;
import com.orange.pamda.worker.starter.CatalogueExportDirectStarter;
import com.orange.pamda.worker.starter.PamdaImportDirectStarter;
import com.orange.pamda.worker.utils.DataFlowParameterInfo;
import com.orange.pamda.worker.utils.Worker;
import com.orange.pamda.worker.utils.WorkerExecutionStatus;
import com.orange.pamda.worker.utils.WorkerParameterInfo;

@RestController
@RequestMapping("dataFlow")
@Transactional
@CrossOrigin
public class DataFlowController {

	private static final Logger LOGGER = LoggerFactory.getLogger(DataFlowController.class);

	@Autowired
	//@Qualifier("catalogueImportDirectStarter")
	CatalogueImportDirectStarter catalogueImportDirectStarter;
	
	@Autowired
	CatalogueExportDirectStarter catalogueExportDirectStarter;
	
	@Autowired
	MappingImportStarter mappingImportStarter;
	
	@Autowired
	MappingExportStarter mappingExportStarter; 
	
	@Autowired
	PamdaImportDirectStarter pamdaImportDirectStarter;
	
	
	@Autowired
	WorkerService workerService;

	@Autowired
	AuthenticationManager authenticationManager;

	@Autowired
	DaoAuthenticationProvider authenticationProvider;
	
	@Autowired
	PamdaServerProperty pamdaProperty;

	@Autowired
	ScopeDao scopeDao;
	
	
	 @RequestMapping(value = "/directExportCatalogue", method = RequestMethod.POST)
	public ResponseEntity<WorkerExecutionStatus> directExportCatalogue(@RequestBody DataFlowParameterInfo dataFlowParameterInfo) {
	
	 WorkerExecutionStatus workerExecutionStatus = new WorkerExecutionStatus();
	 
	 try {
		 	long startTime = System.nanoTime();
			
		 	dataFlowParameterInfo.setDataFlowName(com.orange.pamda.worker.utils.Worker.catalogueImport.name().toString());
		 	catalogueExportDirectStarter.start(dataFlowParameterInfo);
			long endTime = (System.nanoTime() - startTime) / 1000000000;
			LOGGER.trace("[TIMER] Pamda import direct : {}", endTime);
			System.out.println("[TIMER] Pamda import direct : {}"+ endTime);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			
			workerExecutionStatus.setOnError(true);	
			
		}
		return new ResponseEntity<>(workerExecutionStatus, HttpStatus.OK);
	}
	

	@RequestMapping(value = "/directImportCatalogue", method = RequestMethod.POST)
	public ResponseEntity<WorkerExecutionStatus> directImportCatalogue(@RequestBody DataFlowParameterInfo dataFlowParameterInfo) {
	 dataFlowParameterInfo.setDataFlowName(com.orange.pamda.worker.utils.Worker.catalogueImport.name().toString());
	 WorkerExecutionStatus workerExecutionStatus = new WorkerExecutionStatus();
	 
	 try {
		 	long startTime = System.nanoTime();
			
			
			catalogueImportDirectStarter.start(dataFlowParameterInfo);
			long endTime = (System.nanoTime() - startTime) / 1000000000;
			LOGGER.trace("[TIMER] directImportCatalogue : {}", endTime);
			System.out.println("[TIMER] directImportCatalogue : {}"+ endTime);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			
			workerExecutionStatus.setOnError(true);	
			
		} 
		return new ResponseEntity<>(workerExecutionStatus, HttpStatus.OK);
	}
	
	
	@PostMapping(value = "/directImportPamda")
	public ResponseEntity<WorkerExecutionStatus> directImportPamda(@RequestBody DataFlowParameterInfo dataFlowParameterInfo) {
		
	 WorkerExecutionStatus workerExecutionStatus = new WorkerExecutionStatus();
	 
	 try {
		 	long startTime = System.nanoTime();
			
		 	dataFlowParameterInfo.setDataFlowName(com.orange.pamda.worker.utils.Worker.catalogueImport.name().toString());
		 	pamdaImportDirectStarter.start(dataFlowParameterInfo);
			long endTime = (System.nanoTime() - startTime) / 1000000000;
			LOGGER.trace("[TIMER] Pamda import direct : {}", endTime);
			System.out.println("[TIMER] Pamda import direct : {}"+ endTime);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			
			workerExecutionStatus.setOnError(true);	
			
		}
		return new ResponseEntity<>(workerExecutionStatus, HttpStatus.OK);
	}
	
	
	/* @RequestMapping(value = "/directExportMapping", method = RequestMethod.POST)
	public ResponseEntity<Void> directExportMapping(@RequestBody WorkerParameterInfo workerParameterInfo) {
		workerParameterInfo.setWorker(Worker.valueOf(com.orange.pamda.worker.utils.Worker.mappingExport.name()));
		workerService.launch(workerParameterInfo);
		return new ResponseEntity<>(HttpStatus.OK);
	}

	
	
	@RequestMapping(value = "/directImportMapping", method = RequestMethod.POST)
	public ResponseEntity<WorkerExecutionStatus> directImportMapping(@RequestBody WorkerParameterInfo workerParameterInfo) {
		workerParameterInfo.setWorker(Worker.valueOf(com.orange.pamda.worker.utils.Worker.mappingImport.name()));
		List<WorkerExecutionStatus> workerExecutionStatuss = workerService.launch(workerParameterInfo);
		return new ResponseEntity<>(workerExecutionStatuss.get(0), HttpStatus.OK);
	}
	*/
}

and here is the class called by my directImportPamda method for processing :

    package com.orange.pamda.worker.starter;

import java.io.File;
import java.io.IOException;
import java.util.List;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.collect.Lists;
import com.orange.pamda.config.PamdaServerProperty;
import com.orange.pamda.dao.MappingContextDAO;
import com.orange.pamda.entity.jpa.MappingContext;
import com.orange.pamda.service.MappingContextService;
import com.orange.pamda.util.DataFlowParametersBuilder;
import com.orange.pamda.util.DateHelper;
import com.orange.pamda.util.FileFormatter;
import com.orange.pamda.util.FileHelper;
import com.orange.pamda.util.PamdaDataFlowStarter;
import com.orange.pamda.worker.distributon.ArchiveService;
import com.orange.pamda.worker.eraser.DataEraser;
import com.orange.pamda.worker.utils.DataFlowParameterInfo;


@Component("pamdaImportDirect")
public class PamdaImportDirectStarter implements PamdaDataFlowStarter {

	@Inject
	private ArchiveService archiveService;

	@Inject
	private DataEraser dataEraser;
	
	@Autowired
	CatalogueImportDirectStarter catalogueImportDirectStarter;
	
	@Autowired
	CatalogueExportDirectStarter catalogueExportDirectStarter;
	
	@Autowired
	MappingImportStarter mappingImportStarter;
	
	@Autowired
	MappingExportStarter mappingExportStarter;
	
	@Inject
	private PamdaServerProperty pamdaProperty;

	@Autowired
	private MappingContextDAO mappingContextDAO;
	
	@Autowired
	private MappingContextService mappingContextService;

	protected static Logger logger = LoggerFactory.getLogger(PamdaImportDirectStarter.class);
	
	
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public void start(DataFlowParameterInfo dataFlowParameterInfo)
			throws  IOException {
		
		System.out.println("START launching Pamda Import");
		
		
	    startImport(dataFlowParameterInfo);
		System.out.println("End launching Pamda Import JOB");
	
	}

	private void startImport(DataFlowParameterInfo dataFlowParameterInfo) {
		try {
			catalogueExportDirectStarter.start(dataFlowParameterInfo);
		} catch (IOException e3) {
			// TODO Auto-generated catch block
			e3.printStackTrace();
		}
		
		try {
			mappingExportStarter.start(dataFlowParameterInfo);
		} catch (IOException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}
		
		archive(dataFlowParameterInfo);
		
		unZipArchive(dataFlowParameterInfo);
		
		dataEraser(dataFlowParameterInfo);
		
		try {
			catalogueImportDirectStarter.start(dataFlowParameterInfo);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		try {
			mappingImportStarter.start(dataFlowParameterInfo);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		deleteUnZipFiles();
	}
	
	public void archive(DataFlowParameterInfo dataFlowParameterInfo) {
		
		DataFlowParametersBuilder builder = new DataFlowParametersBuilder();

		String pamdaImportPath = pamdaProperty.getPamdaImportPath();

		File[] filesList = null;
		try {
			filesList =		FileHelper.getFilesFromDirectoryMatchingPattern(pamdaImportPath, pamdaProperty.getPamdaFilename());
		} catch(Exception ex) {
			//throw new JobParametersInvalidException(dataFlowParameterInfo.NO_FILE);
		} 
		
		if (filesList != null && filesList.length > 1) 
			//throw new JobParametersInvalidException(dataFlowParameterInfo.TOO_MANY_FILES);
		
		if (filesList != null && filesList.length == 1) {
			MappingContext selectedMappingContext = mappingContextDAO.findMappingContext(Long.parseLong(dataFlowParameterInfo.getCurrentMappingContext()));
			
			//if(!filesList[0].getName().contains(selectedMappingContext.getCode()))
				//throw new JobParametersInvalidException(dataFlowParameterInfo.DIFFERENT_CONTEXT_FILE + "." + filesList[0].getName());
		}
		
	
		
		String parameterPaths = FileHelper.buildSplitFilenameParameter(filesList);

		
		String pamdaFilename = pamdaProperty.getPamdaFilename();
		long startTime = System.currentTimeMillis();
		String exportDateString = DateHelper.FILE_DATE_TIME_FORMATTER.print(startTime);
		
		MappingContext mappCntxt = mappingContextService
				.findById(Long.valueOf(dataFlowParameterInfo.getCurrentMappingContext()));

		List<String> pathList = FileHelper.splitFilesParameter(cataloguePath, catalogueFilename);
		pathList.addAll(FileHelper.splitFilesParameter(mappingPath, mappingFilename));

		String pamdaExportPath = pamdaProperty.getPamdaExportPath();
		File pamdaExportResult;
		
		try {
			pamdaExportResult = FileFormatter.getFormattedFileWithDate(mappCntxt.getCode(), pamdaFilename, ".zip",
					pamdaExportPath, exportDateString);
			archiveService.archiveFiles(pamdaExportPath, pamdaExportResult.getName(), pathList, currentContext , dataFlowParameterInfo.getPamdaVersion().getVersion() , dataFlowParameterInfo.getPamdaVersion().getCommentaire(), dataFlowParameterInfo.getUser(), dataFlowParameterInfo.getPamdaVersion().getFlag());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	
	
	
	private void unZipArchive (DataFlowParameterInfo dataFlowParameterInfo) {
		
		
		String pamdaImportPath = pamdaProperty.getPamdaImportPath();
		File[] filesList = null;
		try {
			filesList =		FileHelper.getFilesFromDirectoryMatchingPattern(pamdaImportPath, pamdaProperty.getPamdaFilename());
		} catch(Exception ex) {
			//throw new JobParametersInvalidException(dataFlowParameterInfo.NO_FILE);
		} 
		String importFilename = FileHelper.buildSplitFilenameParameter(filesList);
		List<String> files = FileHelper.splitFilesParameter(pamdaImportPath, importFilename);
		try {
			archiveService.unZipArchiveFile( files );
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public void dataEraser(DataFlowParameterInfo dataFlowParameterInfo) {
		
		dataEraser.eraseData(Long.parseLong(dataFlowParameterInfo.getCurrentMappingContext()));
	
	}
	
public void deleteUnZipFiles() {
		
		List<File> folderList = Lists.newArrayList();
		folderList.add(FileHelper.getFileFromResource(pamdaProperty.getMappingImportPamdaPath()));
		folderList.add(FileHelper.getFileFromResource(pamdaProperty.getCatalogueImportPamdaPath()));

		try {
			archiveService.deleteArchiveFiles(folderList);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}

and here is the code of my class CatalogExportDirectStarter which is called by the class PamdaImportDirect :

   package com.orange.pamda.worker.starter;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.orange.pamda.config.PamdaServerProperty;
import com.orange.pamda.dao.MappingContextDAO;
import com.orange.pamda.entity.jpa.MappingContext;
import com.orange.pamda.service.MappingContextService;
import com.orange.pamda.util.DataFlowParameters;
import com.orange.pamda.util.DataFlowParametersBuilder;
import com.orange.pamda.util.DateHelper;
import com.orange.pamda.util.FileFormatter;
import com.orange.pamda.util.FileHelper;
import com.orange.pamda.util.PamdaDataFlowStarter;
import com.orange.pamda.worker.catalogue.exporter.CatalogueExporter;
import com.orange.pamda.worker.catalogue.importer.CatalogueImporter;
import com.orange.pamda.worker.service.XMLValidationService;
import com.orange.pamda.worker.utils.DataFlowParameterInfo;


@Component("catalogueExportDirectStarter")
public class CatalogueExportDirectStarter implements PamdaDataFlowStarter {

	@Inject
	@Qualifier("catalogueImporter")
	private CatalogueExporter catalogueExporter;
	
	@Inject
	private XMLValidationService xmlValidationService;
	@Inject
	private PamdaServerProperty pamdaProperty;

	@Autowired
	private MappingContextDAO mappingContextDAO;
	
	@Autowired
	private MappingContextService mappingContextService;

	protected static Logger logger = LoggerFactory.getLogger(PamdaImportDirectStarter.class);
	
	
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public void start(DataFlowParameterInfo dataFlowParameterInfo)
			throws  IOException {

		String pamdaExportPath = pamdaProperty.getPamdaExportPath();
		String pamdaFilename = pamdaProperty.getPamdaFilename();
		

		
		DataFlowParametersBuilder builder = new DataFlowParametersBuilder();
		long startTime = System.currentTimeMillis();

		MappingContext mappCntxt = mappingContextService
				.findById(Long.valueOf(dataFlowParameterInfo.getCurrentMappingContext()));

		String exportDateString = DateHelper.FILE_DATE_TIME_FORMATTER.print(startTime);

		File pamdaCatalogueExportResult = FileFormatter.getFormattedFileWithDate(mappCntxt.getCode(),
				pamdaProperty.getCatalogueFilename(), ".xml", pamdaExportPath, exportDateString);
		builder.addString(cataloguePath, pamdaExportPath);
		builder.addString(catalogueFilename, pamdaCatalogueExportResult.getName());
		builder.addString("catalogueCode", dataFlowParameterInfo.ALL);

		File pamdaMappingExportResult = FileFormatter.getFormattedFileWithDate(mappCntxt.getCode(),
				pamdaProperty.getMappingFilename(), ".xml", pamdaExportPath, exportDateString);
		builder.addString(mappingPath, pamdaExportPath);
		builder.addString(mappingFilename, pamdaMappingExportResult.getName());

		File pamdaExportResult = FileFormatter.getFormattedFileWithDate(mappCntxt.getCode(), pamdaFilename, ".zip",
				pamdaExportPath, exportDateString);
		builder.addString("archiveTargetName", pamdaExportResult.getName());
		builder.addString("archiveTargetDirectory", pamdaExportPath);
		builder.addString(targetFilePathParameterName, "archiveTargetName");
		builder.addLong(datetime, startTime);
		
		builder.addString(currentContext, dataFlowParameterInfo.getCurrentMappingContext());
		builder.addString(disabledByUser, String.valueOf(dataFlowParameterInfo.isDisabledByUser()));
		if(dataFlowParameterInfo.getPamdaVersion() != null) {
			builder.addString("pamdaVersion", dataFlowParameterInfo.getPamdaVersion().getVersion());
			builder.addString("comVersion", dataFlowParameterInfo.getPamdaVersion().getCommentaire());
			builder.addString("login", dataFlowParameterInfo.getUser());
			builder.addDate("flag", dataFlowParameterInfo.getPamdaVersion().getFlag());
		}

		startExport(builder.toDataFlowParameters() );
	}
		public void startExport(DataFlowParameters dataFlowParameters ) { 
			
			
			
			//catalogueExport 
			
			Long mappingSystemId = Long.parseLong(dataFlowParameters.getString(PamdaDataFlowStarter.currentContext));
			List<String> inputFilePaths = new ArrayList<String>();
			inputFilePaths.add(dataFlowParameters.getString(PamdaDataFlowStarter.catalogueFilename));
			
			catalogueExporter.export(dataFlowParameters.getString(PamdaDataFlowStarter.cataloguePath) + File.separator + dataFlowParameters.getString(PamdaDataFlowStarter.catalogueFilename), dataFlowParameters.getString(PamdaDataFlowStarter.catalogueCode), dataFlowParameters.getString(PamdaDataFlowStarter.currentContext));
			
			//catalogueValidation
			catalogueValidation(dataFlowParameters);			
		}
		
		
		public void catalogueValidation(DataFlowParameters dataFlowParameters) {
			String catalogueFilename = dataFlowParameters.getString(PamdaDataFlowStarter.catalogueFilename);
			String filePath = dataFlowParameters.getString(PamdaDataFlowStarter.cataloguePath);
			
			List<String> files = FileHelper.splitFilesParameter(filePath, catalogueFilename);
			xmlValidationService.validate( files, pamdaProperty.getCatalogueXSDfile());
			
			
		}
	
	
}

there are other classes i use but i can't post them because of the 30,000 word limit imposed by stackoverFlow 如何解决使用名称 'dataFlowController' 创建错误 bean 的问题

can someone please help me to resolve this error ?

huangapple
  • 本文由 发表于 2020年4月8日 19:14:54
  • 转载请务必保留本文链接:https://java.coder-hub.com/61099366.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定