Ich bin von Grund auf meiner ersten Frühlings Boot-Anwendung arbeiten und Online den Stil anderer Beispiele usw. gefunden imitiert wurden, ich habe die folgende Verzeichnisstruktur:Keine Qualifikation Bean vom Typ für Abhängigkeit für @Autowired Dienst gefunden
|com.riisan.core
|\
||config
||\
|||RiisanConfig
|||JerseyConfig
||domain
||\
|||Game
|||Player
||repository
||\
|||GameRespository
||resources
||\
|||Games
||service
||\
|||impl
|||\
||||GameServiceImpl
|||GameService
Innerhalb der Hauptkonfigurationsdatei, die ich habe:
@Configuration
@SpringBootApplication
@ComponentScan
@EnableJpaRepositories
public class RiisanConfig {
public static void main(String args[]){
SpringApplication.run(RiisanConfig.class, args);
}
}
ich habe das Spiel und der Spieler mit @Entity
markiert, und das Repository wie folgt aussieht:
@Repository
public interface GameRepository extends JpaRepository<Game, String> {
List<Game> findAll();
}
Meine Ressourcenkomponente ist:
@Component
@Path("/games")
@Api(value = "/games", description = "Games REST")
public class Games {
@Autowired
GameService gameService;
@GET
@ApiOperation(value = "Get all Games", response = Game.class, responseContainer = "List")
@Produces(MediaType.APPLICATION_JSON)
public List<Game> getAllGames(){
return gameService.getAllGames();
}
}
Und schließlich, der Service und die Service-Implementierung sind wie folgt:
public interface GameService {
public List<Game> getAllGames();
public Game saveGame(Game game);
}
@Service
public class GameServiceImpl implements GameService {
@Autowired
GameRepository gameRepository;
public List<Game> getAllGames() {
return gameRepository.findAll();
}
public Game saveGame(Game game) {
return null;
}
}
Alles funktioniert, um die GET
Anfrage zu schaffen. Auf die GET-Anforderung empfängt, erhalte ich eine Fehlermeldung:
No qualifying bean of type [com.riisan.core.service.GameService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.
Ich habe versucht, alle Schritte in anderen Beiträgen SE, wie @Service
-@Service("gameService")
Ändern oder Hinzufügen @Qualifier
, aber ohne Erfolg. Diese Struktur und alle Annotationen spiegeln die einer funktionierenden Anwendung wider, die ich als Basis für den Versuch, diese Anwendung einzurichten, verwendet habe, mit der geringfügigen Optimierung, dass die funktionierende Anwendung ein MongoRepository anstelle von JpaRepository verwendet. Was verursacht diesen Fehler?
UPDATE: unten einige der Antworten Versuch habe ich versucht:
@Configuration
@SpringBootApplication
@ComponentScan(basePackages = "com.riisan.core")
@EnableJpaRepositories
public class RiisanConfig {
public static void main(String args[]){
SpringApplication.run(RiisanConfig.class, args);
}
}
Diese in den folgenden Fehlern führt bei Start der Anwendung:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'games': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.riisan.core.service.GameService com.riisan.core.resources.Games.gameService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gameServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.riisan.core.repository.GameRepository com.riisan.core.service.impl.GameServiceImpl.gameRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.riisan.core.repository.GameRepository] 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 ... ...
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.riisan.core.service.GameService com.riisan.core.resources.Games.gameService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gameServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.riisan.core.repository.GameRepository com.riisan.core.service.impl.GameServiceImpl.gameRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.riisan.core.repository.GameRepository] 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 ... ...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gameServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.riisan.core.repository.GameRepository com.riisan.core.service.impl.GameServiceImpl.gameRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.riisan.core.repository.GameRepository] 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 ... ...
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.riisan.core.repository.GameRepository com.riisan.core.service.impl.GameServiceImpl.gameRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.riisan.core.repository.GameRepository] 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 ... ...
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.riisan.core.repository.GameRepository] 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)}
ich das Paket zusätzlich versucht, die Auflistung für die Repository in `@EnableJpaRepositories (" com.riisan.core.repsiony "), das zu Not an managed type führt. Ich habe versucht, die dort aufgelistete Antwort zu kopieren, aber die Verzeichnisstruktur ist anders, was wahrscheinlich das Problem verursacht.
Möglicherweise müssen Sie GameServiceImpl mit '@ Component' annotieren. –
Verschieben Sie Ihre 'Games' Klasse in' com.riisan.core' Entfernen Sie alle Anmerkungen außer '@ SpringBootApplication' ... Starten Sie dann Ihre Anwendung neu. Jetzt wird alles automatisch erkannt und abgeholt. –