2013-06-25 5 views
1

Когда я бегу Cobertura, это приводит к ошибке следующие Spring автоматического связывания:Spring автоматического связывания сбиваться при использовании Cobertura

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userResource': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dnb.components.storage.service.UserService com.dnb.components.storage.rest.resource.UserResource.userService; nested exception is java.lang.IllegalArgumentException: Can not set com.dnb.components.storage.service.UserService field com.dnb.components.storage.rest.resource.UserResource.userService to com.sun.proxy.$Proxy56 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)


как предложено в других соответствующих должностей, я попытался принуждая Spring использовать CGLIB путем изменения «proxyTargetClass = истина», но это приводит к различной ошибки:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userResource': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dnb.components.storage.service.UserService com.dnb.components.storage.rest.resource.UserResource.userService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.dnb.components.storage.repository.UserRepository com.dnb.components.storage.service.UserService.repository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Post-processing of the FactoryBean's object failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.sun.proxy.$Proxy54]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class com.sun.proxy.$Proxy54

Это то, что Repository класс выглядит следующим образом:

@Transactional 
public interface UserRepository extends CrudRepository<User, Long> { 

    public User findByCrmId(String crmIdId); 
} 

Вот это услуга, которая получает инъекцию UserRepository:

@Service 
@Transactional 
public class UserService extends TraceablePersistenceService<User, UserRepository> { 

    @Autowired 
    UserRepository repository; 

    @Transactional 
    public Iterable<User> findAll() { 
     return repository.findAll(); 
    } 

    public User findOne(Long id) { 
     return repository.findOne(id); 
    } 
} 

Наша конфигурация в

@Configuration 
@EnableTransactionManagement(proxyTargetClass=true) 
@EnableJpaRepositories(basePackages = {"com.dnb.components.storage.repository"}) 
@Profile("inmemory") 
public class InMemoryStandaloneStorageConfig extends BasicJpaStorageConfig { 

.... 

(для краткости опущены)

UserResource.java:

@Component 
@Path(UserResource.uri) 
public class UserResource extends AbstractResource { 
    public final static String uri = BASE_URI + "/users"; 

    @Override 
    public String getURI() { 
     return BASE_URI + uri; 
    } 

    @Autowired 
    private UserService userService; 

...

Похоже, что сгенерированный класс репозитория Spring Data JPA не может быть проксимирован в любом случае, не завинчивая автоматическую проводку.

Есть ли исправление для этого? Это даже хорошая идея, чтобы комментировать методы репозитория с помощью @Transactional? Если аннотация должна быть только на уровне обслуживания?

+0

Покажите нам объявление поля com.dnb.components.storage.rest.resource.UserResource.userService – Jukka

ответ

0

Обычно мы не вводим классы конкретных классов, но вводим интерфейсы. это мое предложение.

a. рефакторинг UserService для UserServiceImpl класс

b. создать интерфейс UserService

c. UserServiceImpl реализует UserService

d. добавить объявление «findAll» и «findOne» в интерфейс UserService