Insatisfait de la dépendance exprimée à travers le champ 'jdbcTemplate'
J'ai vraiment besoin d'aide ici..
J'ai essayé de créer simple webapps springboot avec dépendances: web, postgresql, jdbc, vaadin.
Quand commencer à exécuter mes applications, les applications risquent de ne pas démarrer et il y a des exception levée.
L'exception dire "..pas de qualification bean de type JdbcTemplate".
Certains suggestion dans stackoverflow pour ajouter artefact printemps-amorçage-starter-jdbc, mais mon pom déjà fait et ne fonctionne toujours pas.
Ci-dessous ma config
src/main/resources/de l'application.propriétés:
spring.datasource.url=jdbc:postgresql://localhost:5432/sehati
spring.datasource.username=sehati
spring.datasource.password=password
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sehatigroup</groupId>
<artifactId>siapotek</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>siapotek</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring-boot-starter</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<!--
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<version>7.6.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Classe principale:
@SpringBootApplication
public class SiaApplication {
public static void main(String[] args) {
SpringApplication.run(SiaApplication.class, args);
}
}
VadinUI:
@SpringUI
@Theme("valo")
public class SehatiDashboardUI extends UI {
@Override
protected void init(VaadinRequest request) {
setContent(new Label("Hello World"));
}
}
Printemps composant:
@Component
public class LookupService {
@Autowired
private JdbcTemplate jdbcTemplate;
public List<Lookup> findAll() {
return jdbcTemplate.query("select id, type, label, name from lookup",
(rs, rowNum) -> new Lookup(rs.getLong("id"), rs.getString("type"), rs.getString("label"), rs.getString("label")));
}
}
La sortie de la console:
. ____ _ __ _ _
/\\ /___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/_` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | ////
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.0.RELEASE)
2016-08-15 07:03:09.329 INFO 1387 --- [ main] com.sehatigroup.SiaApplication : Starting SiaApplication on learn2fly with PID 1387 (/home/hameed/workspace/siapotek/target/classes started by hameed in /home/hameed/workspace/siapotek)
2016-08-15 07:03:09.333 INFO 1387 --- [ main] com.sehatigroup.SiaApplication : No active profile set, falling back to default profiles: default
2016-08-15 07:03:09.530 INFO 1387 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5656be13: startup date [Mon Aug 15 07:03:09 WIB 2016]; root of context hierarchy
2016-08-15 07:03:11.329 WARN 1387 --- [ main] o.s.c.a.ConfigurationClassPostProcessor : Cannot enhance @Configuration bean definition 'com.vaadin.spring.VaadinConfiguration' since its singleton instance has been created too early. The typical cause is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor return type: Consider declaring such methods as 'static'.
2016-08-15 07:03:11.892 INFO 1387 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-08-15 07:03:12.069 INFO 1387 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$666445bd] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-08-15 07:03:12.776 INFO 1387 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-08-15 07:03:12.795 INFO 1387 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2016-08-15 07:03:12.797 INFO 1387 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.4
2016-08-15 07:03:12.931 INFO 1387 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-08-15 07:03:12.932 INFO 1387 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3414 ms
2016-08-15 07:03:13.065 INFO 1387 --- [ost-startStop-1] c.v.s.b.i.VaadinServletConfiguration : Registering Vaadin servlet
2016-08-15 07:03:13.065 INFO 1387 --- [ost-startStop-1] c.v.s.b.i.VaadinServletConfiguration : Servlet will be mapped to URLs [/vaadinServlet/*, /VAADIN/*]
2016-08-15 07:03:13.086 INFO 1387 --- [ost-startStop-1] c.v.s.b.i.VaadinServletConfiguration : Setting servlet init parameters
2016-08-15 07:03:13.086 INFO 1387 --- [ost-startStop-1] c.v.s.b.i.VaadinServletConfiguration : Set servlet init parameter [productionMode] = [false]
2016-08-15 07:03:13.086 INFO 1387 --- [ost-startStop-1] c.v.s.b.i.VaadinServletConfiguration : Set servlet init parameter [resourceCacheTime] = [3600]
2016-08-15 07:03:13.087 INFO 1387 --- [ost-startStop-1] c.v.s.b.i.VaadinServletConfiguration : Set servlet init parameter [heartbeatInterval] = [300]
2016-08-15 07:03:13.087 INFO 1387 --- [ost-startStop-1] c.v.s.b.i.VaadinServletConfiguration : Set servlet init parameter [closeIdleSessions] = [false]
2016-08-15 07:03:13.218 INFO 1387 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-08-15 07:03:13.218 INFO 1387 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-08-15 07:03:13.219 INFO 1387 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-08-15 07:03:13.219 INFO 1387 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2016-08-15 07:03:13.221 INFO 1387 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2016-08-15 07:03:13.221 INFO 1387 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2016-08-15 07:03:13.223 INFO 1387 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'springVaadinServlet' to [/vaadinServlet/*, /VAADIN/*]
2016-08-15 07:03:13.302 WARN 1387 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'lookupService': Unsatisfied dependency expressed through field 'jdbcTemplate': No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency [org.springframework.jdbc.core.JdbcTemplate]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency [org.springframework.jdbc.core.JdbcTemplate]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2016-08-15 07:03:13.307 INFO 1387 --- [ main] o.apache.catalina.core.StandardService : Stopping service Tomcat
2016-08-15 07:03:13.338 WARN 1387 --- [ main] 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]: Initialization 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' is defined)
2016-08-15 07:03:13.355 ERROR 1387 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'lookupService': Unsatisfied dependency expressed through field 'jdbcTemplate': No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency [org.springframework.jdbc.core.JdbcTemplate]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency [org.springframework.jdbc.core.JdbcTemplate]: 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$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:569) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:349) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:776) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
at com.sehatigroup.SiaApplication.main(SiaApplication.java:10) [classes/:na]
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency [org.springframework.jdbc.core.JdbcTemplate]: 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.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1406) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1057) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1019) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:566) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
... 19 common frames omitted
Et aussi j'ai essayer de l'utilisation de la base de données H2. Mes applications peuvent commencé, mais seemslike connexion de source de données, utilisez toujours pré-configuré source de données à partir du printemps-boot-jdbc (url='jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false', username='sa'
), même que j'ai déjà décrit la nouvelle application.les propriétés.
Quelqu'un pourrait-il trouver ce qui ne va pas avec mon projet?
Vraiment reconnaissant de votre aide.
DataSource
dans votre système. La configuration dans application.properties
assurez-vous de créer un DataSource
bean pour vous. Se pourrait-il que vous êtes en train de créer la source de données vous-même? Exécutez votre application avec "--debug" et vous obtenez un rapport qui explique pourquoi la JdbcTemplateAutoConfiguration n'était pas activé.Salut @Stephane. Merci pour l'idée. Je n'ai qu'une source de données configuré dans l'application.propriétés et autant que je sache, aucune autre source de données créée. Mon éclipse totale du projet peut être l'accès [ici] (dropbox.com/s/wgee2bgoc9hkrx8/siapotek.tar.gz?dl=0). Merci de bien vouloir consulter mon projet.
J'ai aussi essayer de déboguer le projet, mais je n'ai aucune idée à l'exception levée dans eclipse console. Une ligne de sortie de me rendre curieux, il a dit "Sauté (vide) fichier de config...", j'ai vérifié l'application.propriétés contiennent déjà de la source de données de config
Euh? J'ai téléchargé le projet et il fonctionne très bien pour moi. J'ai pu démarrer l'application et allez à la page d'accueil. J'ai pu tester. Pas d'exception.
Merci @StephaneNicoll. Il est des sons comme "environnement" problème pour moi. J'ai nettoyer le projet, déplacez-projet à l'autre de l'espace de travail..mais encore le même problème. J'utilise eclipse néon (4.6.0) avec le plugin: printemps IDE 3.8.1. Avez-vous une idée?
OriginalL'auteur Midoen | 2016-08-15
Vous devez vous connecter pour publier un commentaire.
J'ai essayer de nouvelles IDE (eclipse, sts), de créer de nouveaux espace de travail, importer le projet, créer un nouveau projet, mais toujours face à un problème.
Enfin mes applications peuvent fonctionner après le retrait de mon .m2 dossier. Mais je ne sais toujours pas ce qui s'est passé dans mon mvn référentiel.
Merci
OriginalL'auteur Midoen
Il semble que si vous n'avez pas créé de JdbcTemplate haricot dans la configuration de la classe, de sorte que le printemps ne sais pas quoi injecter dans votre JdbcTemplate lorsque votre application démarre.
Voici un exemple qui montre comment configurer votre JdbcTemplate à partir d'une source de données de haricots dans votre configuration spring: http://www.concretepage.com/spring/jdbc-template-spring-jdbc-integration-example
Ah, il semble que vous avez raison 🙂 mais j'ai lu le readme et il a les informations suivantes: "le Printemps de Démarrage des taches H2, une mémoire relationnelle moteur de base de données, et crée automatiquement une connexion. Parce que nous sommes à l'aide de printemps-jdbc, Spring Boot crée automatiquement un JdbcTemplate. @Autocâblés JdbcTemplate champ automatiquement la charge et le rend disponible." Étant donné qu'il semble avoir besoin d'H2 à injecter le JdbcTemplate, est-il une raison pour laquelle vous avez commenté dans votre pom.. ?
Vous n'avez pas besoin de H2 pour obtenir un JdbcTemplate. Tant qu'il y est une source de données (sur n'importe quel type de base de données), nous allons configurer automatiquement un JdbcTemplate.
À propos de H2 dans mon pompon, auparavant, j'ai litle expérience à l'aide de H2 pilote pour voir si le printemps-démarrage, utiliser mon application.propriétés ou pas. Et j'ai trouvé printemps-boot ne pas utiliser ou de lire ma demande.fichier de propriétés. J'ai configurer l'url jdbc utilisation H2 fichier (et non pas dans la mémoire de défaut H2 source de données). Lorsque les applications ont commencé, dit-on de source de données, utilisez url='jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false', pseudo='sa'. Après que j'ai commenté H2 pilote, et de revenir à PostgreSQL.
OriginalL'auteur Pete