1

We have Spring (3.0.6) @WebSerice working fine with @Autowried to @Service and @Repository with Java 7.

Recently, we need to upgrade to Java 8 then the repository class can not @Autowired.

Very simple Resposity:

@Repository
public interface MyClss extends JpaRepository<MyData, String> {
    MyData findOne( String key );
}

Is there any difference in @Autowrited from Java 7 to Java 8 in Spring?

Tiny
  • 27,221
  • 105
  • 339
  • 599
Nam Vu
  • 161
  • 1
  • 4
  • What is the error you are getting? – Balwinder Singh Sep 15 '15 at 01:58
  • Ah sorry, i foget the error : Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type ... 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)}.... – Nam Vu Sep 15 '15 at 02:02
  • But something weird, We enable Jrebel on my local develop server Tomcat, It work with Java 8. – Nam Vu Sep 15 '15 at 02:05
  • It might be because of the fact that your Context is unable to load properly and thus Spring is not able to initialize any Beans. It is one of the most common error I have ever seen. – user2004685 Sep 15 '15 at 03:41

2 Answers2

0

I think @Repository is only for use on classes, not interfaces. If this is a Spring 3 app, you must either compile the code as java 7 or upgrade to Spring 4. See spring-core 3.2.9 + java 8

Community
  • 1
  • 1
Brad
  • 2,261
  • 3
  • 22
  • 32
0

Because our legacy project very old containing many old lib and packages, we can not upgrade to Spring 4 or upper 3.2.

We fixed the problem, when figure out that the top lever are using CXF Webservice ( 2.x ). That CXF version not support Java 8.

Spring bean not injected into CXF web service, Why?

So, instead of using @Autowired, we change to get the Service Class with @Repository by ApplicationContext, It's work.

Ex: OrderService orderService = applicationContextProvider.getApplicationContext().getBean(OrderService.class);

Community
  • 1
  • 1
Nam Vu
  • 161
  • 1
  • 4