Note that there are some explanatory texts on larger screens.

plurals
  1. PO'Could not autowire field' exception in Spring
    text
    copied!<p>I have a <a href="http://en.wikipedia.org/wiki/Spring_Framework" rel="nofollow">Spring</a> application and am using Spring version 3.0.4. When I start the server it shows me an error:</p> <pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.domain.Custom org.controller.CustomController.custom; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.domain.Custom] 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:288) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1095) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:516) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:381) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) </code></pre> <h3>Code for the domain class</h3> <pre><code>@Entity @Configurable @Table(name="tbltest") public class Custom implements Serializable{ @Autowired public transient CustomRepository customRepository; public static CustomRepository getRepository() { CustomRepository repository = new Custom().CustomRepository; return repository; } @Transactional(readOnly = true) public static Custom find(final Long id) { return getRepository().find(id); } } </code></pre> <h3>Included configurations in application context</h3> <pre><code>&lt;context:load-time-weaver/&gt; &lt;context:spring-configured /&gt; &lt;context:annotation-config /&gt; &lt;context:component-scan base-package="org.domain.custom"/&gt; </code></pre> <h3>Code for my test class:</h3> <pre><code>@Test @Transactional public void testCreateNew() { Custom registration = new Custom("ttt"); Custom.find(1l); registration.persist(); Assert.assertEquals(true, registration.getId() &gt; 0); } </code></pre> <h3>Controller</h3> <pre><code>@Controller @RequestMapping("/custom") public class CustomController { @Autowired public Custom Custom; } </code></pre> <p>And I have added <code>spring-instrument.jar</code> for the VM argument.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload