У меня есть приложение Spring , и я использую Spring версии 3.0.4.
Когда я запускаю сервер, он показывает мне ошибку:
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)
Код для класса домена
@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);
}
}
Включенные конфигурации в контексте приложения
<context:load-time-weaver/>
<context:spring-configured />
<context:annotation-config />
<context:component-scan base-package="org.domain.custom"/>
Код для моего тестового класса:
@Test
@Transactional
public void testCreateNew() {
Custom registration = new Custom("ttt");
Custom.find(1l);
registration.persist();
Assert.assertEquals(true, registration.getId() > 0);
}
Контроллер
@Controller
@RequestMapping("/custom")
public class CustomController
{
@Autowired
public Custom Custom;
}
И я добавил spring-instrument.jar
для аргумента VM.