2016-11-25 6 views
-1

Ich habe mein Spring Boot Projekt als Single Maven Projekt getestet und alles hat gut funktioniert. Ich entschied mich, meine Anwendung in Submodule zu teilen. Repository, Service und das Spring-Boot-Web-Modul. Der Autowired hört auf zu arbeiten. Und der folgende Fehler aufgetreten:RestController benötigt eine Service Bean mit Spring Boot & Multi Modulen

20:12:08.052 [main] WARN o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userRestController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.plendo.service.interfaces.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
20:12:08.068 [main] WARN o.s.boot.SpringApplication - Error handling failed (Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available) 
20:12:08.243 [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter - `` 
*************************** 
APPLICATION FAILED TO START 
*************************** 
Description: 
Field userService in org.plendo.ui.controller.UserRestController required a bean of type 'org.plendo.service.interfaces.UserService' that could not be found. 
+0

Das sind nicht genug Informationen. Haben Sie z.B. Ändern Sie Ihre Paketstruktur? Wie sehen Ihre Projektstruktur- und Konfigklassen aus? – dunni

Antwort

1

Die Projektstruktur: parent Projekt, das JPA-Modul, Servicemodul und Web-Modul (Feder Boot app)

  • Feder Boot-Anwendung Klasse enthält: Web-Modul

    package org.plendo.ui;  
    @SpringBootApplication public class App { public static void main(String[] args) { 
    @SpringBootApplication 
    public class App { 
    public static void main(String[] args) { 
        SpringApplication.run(App.class, args); 
    } 
        } 
    
  • RestController Klasse: Web-Modul

    package org.plendo.ui.controller; 
    import org.plendo.jpa.entity.User; 
    
    import org.plendo.service.interfaces.UserService; 
    import org.springframework.beans.factory.annotation.Autowired; 
    import org.springframework.context.annotation.ComponentScan; 
    import org.springframework.web.bind.annotation.RequestMapping; 
    import org.springframework.web.bind.annotation.RestController; 
    
    @RestController 
    //@ComponentScan("org.plendo.service.interfaces") 
    public class UserRestController { 
    
    @Autowired 
    //@Qualifier("userService") 
    private UserService userService; 
    
    @RequestMapping(value = "/saveUser") 
    public User saveUser(User u) { 
        return userService.saveUser(u); 
    } 
    } 
    
  • UserServiceImpl: Servicemodul

    import org.apache.log4j.Logger; 
    import org.plendo.jpa.entity.User; 
    import org.plendo.jpa.entity.UserRepository; 
    import org.plendo.service.interfaces.UserService; 
    import org.springframework.beans.factory.annotation.Autowired; 
    import org.springframework.beans.factory.annotation.Qualifier; 
    import org.springframework.stereotype.Service; 
    
    @Service 
    public class UserServiceImpl implements UserService { 
    
    private Logger logger = Logger.getLogger(this.getClass()); 
    @Autowired 
    UserRepository userRepository; 
    
    @Override 
    public User saveUser(User u) { 
        return userRepository.save(u); 
    } 
    

    }

  • Userservice-Schnittstelle: Servicemodul

    package org.plendo.service.interfaces; 
    
    import org.plendo.jpa.entity.User; 
    import org.springframework.beans.factory.annotation.Qualifier; 
    import org.springframework.stereotype.Service; 
    
    public interface UserService { 
    
    public User saveUser(User u); 
    } 
    
  • UserRepository Schnittstelle: JPA-Modul

    package org.plendo.jpa.entity; 
    
    import org.springframework.data.jpa.repository.JpaRepository; 
    
    public interface UserRepository extends JpaRepository<User, String>{ 
    
    } 
    

    Es gibt noch etwas zu tun?

Verwandte Themen