2016-08-15 15 views
1

私は春に基づいている会社が要求するカスタムフレームワークを使用しているJava開発者です。私は古いバージョンのものを動作させることができますが、この新しいリリースでは、Beanがスキャンされているにもかかわらず@Repositoryは@Autowiredできないという問題があります。ここで@Repositoryの@Autowireが失敗しています

エラー

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobInvoiceServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private foo.repository.impl.JobInvoiceRepositoryImpl foo.service.impl.JobInvoiceServiceImpl.jobInvoiceRepositoryImpl; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [foo.repository.impl.JobInvoiceRepositoryImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 
    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:772) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5003) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5517) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private foo.repository.impl.JobInvoiceRepositoryImpl foo.service.impl.JobInvoiceServiceImpl.jobInvoiceRepositoryImpl; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [foo.repository.impl.JobInvoiceRepositoryImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) 
    ... 22 more 
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [foo.repository.impl.JobInvoiceRepositoryImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) 
    ... 24 more 

Aug 15, 2016 5:09:17 PM com.sun.faces.config.ConfigureListener contextInitialized 
INFO: Initializing Mojarra 2.2.5 (20140108-1427 https://svn.java.net/svn/mojarra~svn/tags/[email protected]) for context '/invoicer-application-war' 
0 [localhost-startStop-1] WARN org.springframework.web.context.support.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobInvoiceServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private foo.repository.impl.JobInvoiceRepositoryImpl foo.service.impl.JobInvoiceServiceImpl.jobInvoiceRepositoryImpl; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [foo.repository.impl.JobInvoiceRepositoryImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
19 [localhost-startStop-1] ERROR org.springframework.web.context.ContextLoader - Context initialization failed 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobInvoiceServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private foo.repository.impl.JobInvoiceRepositoryImpl foo.service.impl.JobInvoiceServiceImpl.jobInvoiceRepositoryImpl; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [foo.repository.impl.JobInvoiceRepositoryImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 
    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:772) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5003) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5517) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private foo.repository.impl.JobInvoiceRepositoryImpl foo.service.impl.JobInvoiceServiceImpl.jobInvoiceRepositoryImpl; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [foo.repository.impl.JobInvoiceRepositoryImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) 
    ... 22 more 
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [foo.repository.impl.JobInvoiceRepositoryImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) 
    ... 24 more 

そして、ここでは、アプリケーションのコードです:

@Controller

package foo.controller; 

import java.io.Serializable; 
import java.util.ArrayList; 
import java.util.List; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.context.annotation.Scope; 
import org.springframework.stereotype.Component; 
import org.springframework.stereotype.Controller; 

import foo.domain.JobInvoiceBean; 
import foo.service.impl.JobInvoiceServiceImpl; 

@SuppressWarnings("unused") 
@Component 
@Scope("view") 
public class InvoiceSearchController implements Serializable { 

    private static final long serialVersionUID = -1124694025090601008L; 

    private List<JobInvoiceBean> jobInvoiceList = new ArrayList<JobInvoiceBean>(); 
    private List<JobInvoiceBean> filteredJobInvoices = new ArrayList<JobInvoiceBean>(); 

    private JobInvoiceBean selectedJobInvoice; 

    @Autowired 
    private JobInvoiceServiceImpl jobInvoiceServiceImpl; 

    public void init() { 
     List<JobInvoiceBean> jobInvoiceList = jobInvoiceServiceImpl.getAllJobInvoice(); 
    } 


// public void getJobInvoiceDetail() { 
//  getJobInvoiceDetail(this.selectedJobInvoice); 
// } 
// 
// private void getJobInvoiceDetail(JobInvoiceBean jobInvoiceBean){ 
//  //This is essentially just a re-fetch 
//  JobInvoiceBean jobInvoice = jobInvoiceService.findJobInvoiceById(jobInvoiceBean.getInvoiceNo()); 
//  
//  jobInvoiceBean = jobInvoice; 
// } 

    /* 
    public void onPropertyEdit(CellEditEvent event) { 

     DataTable dataTable = (DataTable) event.getSource(); 
     PropertyBean modifiedProperty = (PropertyBean) dataTable.getRowData(); 

     Property property = jobInvoiceService.findPropertyById(modifiedProperty.getId()); 
     BeanUtils.copyProperties(modifiedProperty, property, "surface", "addresses"); 
     property.setSurface(BigDecimal.valueOf(modifiedProperty.getSurface())); 

     jobInvoiceService.saveOrUpdateProperty(property); 

     FacesMessage msg = new FacesMessage(
       getBundleMessage("property.edition.message"), 
       modifiedProperty.getName()); 
     FacesContext.getCurrentInstance().addMessage(null, msg); 
    } 

    */ 

    public JobInvoiceBean getSelectedJobInvoice() { 
     return selectedJobInvoice; 
    } 

    public void setSelectedJobInvoice(JobInvoiceBean selectedJobInvoice) { 
     this.selectedJobInvoice = selectedJobInvoice; 
    } 


    public List<JobInvoiceBean> getJobInvoiceList() { 
     return jobInvoiceList; 
    } 


    public void setJobInvoiceList(List<JobInvoiceBean> jobInvoiceList) { 
     this.jobInvoiceList = jobInvoiceList; 
    } 


    public List<JobInvoiceBean> getFilteredJobInvoices() { 
     return filteredJobInvoices; 
    } 


    public void setFilteredJobInvoices(List<JobInvoiceBean> filteredJobInvoices) { 
     this.filteredJobInvoices = filteredJobInvoices; 
    } 


} 

@Service

package foo.service.impl; 

import java.util.List; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Service; 

import foo.domain.JobInvoiceBean; 
import foo.repository.impl.JobInvoiceRepositoryImpl; 
import foo.service.JobInvoiceService; 

@Service 
public class JobInvoiceServiceImpl implements JobInvoiceService { 

    @Autowired 
    private JobInvoiceRepositoryImpl jobInvoiceRepositoryImpl; 

    @Override 
    public List<JobInvoiceBean> getAllJobInvoice() { 
     return jobInvoiceRepositoryImpl.getAllInvoices(); 
    } 

} 

@Repository

package foo.repository.impl; 

import java.util.ArrayList; 
import java.util.List; 
import java.util.Map; 

import javax.sql.DataSource; 

import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.context.annotation.ComponentScan; 
import org.springframework.core.convert.ConversionService; 
import org.springframework.jdbc.core.BeanPropertyRowMapper; 
import org.springframework.jdbc.core.simple.SimpleJdbcCall; 
import org.springframework.stereotype.Repository; 
import org.springframework.transaction.annotation.Transactional; 

import foo.domain.JobInvoiceBean; 
import foo.repository.CustomJobInvoiceRepository; 

@Transactional(readOnly = true) 
@SuppressWarnings("unchecked") 
@Repository 
public class JobInvoiceRepositoryImpl implements CustomJobInvoiceRepository { 

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

    private BeanPropertyRowMapper<JobInvoiceBean> invoiceRowMapper; 

    private SimpleJdbcCall simpleJdbcCall; 
    private DataSource dataSource; 

    @Override 
    public List<JobInvoiceBean> getAllInvoices() { 
     List<JobInvoiceBean> listInvoice = new ArrayList<JobInvoiceBean>(); 
     try{ 
      simpleJdbcCall = new SimpleJdbcCall(dataSource); 

      simpleJdbcCall.withCatalogName("invoicer_pkg") 
         .withFunctionName("get_job_invs") 
         .returningResultSet("ret_cursor", invoiceRowMapper); 

//   SqlParameterSource in = new MapSqlParameterSource() 
//    .addValue("clientReference", clientReference) 
//    .addValue("hasChildren", hasChildren ? "Y" : "N"); 

      Map<String, Object> result = simpleJdbcCall.execute();   

      if (result != null && result.size() > 0) { 
       listInvoice = (List<JobInvoiceBean>) result.get("ret_cursor"); 
      } 

     } catch (Exception e) { 
      LOGGER.error(e.getMessage()); 
     }  
     return listInvoice; 
    } 

    @Autowired 
    public void setDataSource(DataSource dataSource) { 
     this.dataSource = dataSource; 
    } 

    @Autowired 
    public void setConversionService(final ConversionService conversionService) { 
     this.invoiceRowMapper = new BeanPropertyRowMapper<JobInvoiceBean>(JobInvoiceBean.class);   
    } 
} 

おそらく私が紛失しているものがありますが、私はそれを見ることはできません。

ありがとうございます。あなたが自動検出コンポーネントの場合のSpring Beanに変えなければ、この@Repository(「のbeanName」)と@Service(「のbeanName」)のように、すべての

+0

例外は、 'CustomJobInvoiceRepositoryImpl'を探していることを示しています。これはappあなたが投稿したコードのどこにでも耳をつけてください。したがって、例外が間違っているか、コード例が完全ではありません。 – dunni

+0

私は最近、スタータークラスを持つパッケージのサブパッケージにないので、クラスを見つけられなかった@Autowiredに問題がありました。これはここで問題になるのでしょうか? –

+0

あなたのクライアント/雇用者のパッケージ名をスタックトレースで隠すべきでしょう:) –

答えて

0

をパッケージ化します。

Spring AOPトランザクションインフラストラクチャはトランザクションを検出し、CustomJobInvoiceRepositoryを実装し、JobInvoiceRepositoryImplに委譲するトランザクションJDKプロキシを作成します。

アプリケーションコンテキストの実際のBeanは、もはやJobInvoiceRepositoryImplではなくプロキシです。

あなたはそれ以外の場合は、XML

<tx:annotation-driven proxy-target-class="true"/> 
でCGLIB例えば

@EnableTransactionManagement(proxyTragetClass = true) 

または等価性を使用して、クラスベースのプロキシを使用するように春に指示

@Service 
public class JobInvoiceServiceImpl implements JobInvoiceService { 

    @Autowired 
    private CustomJobInvoiceRepository jobInvoiceRepository; 

    @Override 
    public List<JobInvoiceBean> getAllJobInvoice() { 
     return jobInvoiceRepository.getAllInvoices(); 
    } 

} 

を次のようにではなくインタフェースを使用JobInvoiceRepositoryImplを注入can`t

0

、あなたは@Autowiredを使用する必要があります。 Implのインタフェースではない次に、このBeanの実装が複数ある場合は、@Qualifierアノテーションを使用します。 Beanがまだスキャンされていない場合は、おそらくあなたは@Component (@Repository, @Serviceなどをスキャンする@ComponentScanを設定する必要があります)あなたのJobInvoiceRepositoryImplクラスはCustomJobInvoiceRepositoryインタフェースを実装し、@Transactionalでアノテートされ

0

まず宣言する必要が

関連する問題