J'essaie de démarrer une simple application de printemps
J'ai le fichier main.Java ici:
package main;
import javafx.application.Application;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan
@EnableAutoConfiguration
public class Main {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Voici les libs que j'ai:
Voici 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>blog</groupId>
<artifactId>blog</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Et finalement l'erreur est celle-ci:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.0.0.BUILD-SNAPSHOT)
[2014-02-15 11:14:25.385] - 6116 INFO [main] --- main.Main: Starting Main on Vlad-PC with PID 6116 (C:\Users\Vlad\IdeaProjects\blog\target\classes started by Vlad)
[2014-02-15 11:14:25.473] - 6116 INFO [main] --- org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext: Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2ca76650: startup date [Sat Feb 15 11:14:25 GMT 2014]; root of context hierarchy
[2014-02-15 11:14:25.579] - 6116 INFO [main] --- org.springframework.boot.logging.ClasspathLoggingApplicationListener: Application failed to start with classpath: [file:/C:/Program%20Files/Java/jdk1.7.0_51/jre/lib/charsets.jar, file:/C:/Program%20Files/Java/jdk1.7.0_51/jre/lib/deploy.jar, file:/C:/Program%20Files/Java/jdk1.7.0_51/jre/lib/javaws.jar, file:/C:/Program%20Files/Java/jdk1.7.0_51/jre/lib/jce.jar, file:/C:/Program%20Files/Java/jdk1.7.0_51/jre/lib/jfr.jar, file:/C:/Program%20Files/Java/jdk1.7.0_51/jre/lib/jfxrt.jar, file:/C:/Program%20Files/Java/jdk1.7.0_51/jre/lib/jsse.jar, file:/C:/Program%20Files/Java/jdk1.7.0_51/jre/lib/management-agent.jar, file:/C:/Program%20Files/Java/jdk1.7.0_51/jre/lib/plugin.jar, file:/C:/Program%20Files/Java/jdk1.7.0_51/jre/lib/resources.jar, file:/C:/Program%20Files/Java/jdk1.7.0_51/jre/lib/rt.jar, file:/C:/Program%20Files/Java/jdk1.7.0_51/jre/lib/ext/access-bridge-64.jar, file:/C:/Program%20Files/Java/jdk1.7.0_51/jre/lib/ext/dnsns.jar, file:/C:/Program%20Files/Java/jdk1.7.0_51/jre/lib/ext/jaccess.jar, file:/C:/Program%20Files/Java/jdk1.7.0_51/jre/lib/ext/localedata.jar, file:/C:/Program%20Files/Java/jdk1.7.0_51/jre/lib/ext/sunec.jar, file:/C:/Program%20Files/Java/jdk1.7.0_51/jre/lib/ext/sunjce_provider.jar, file:/C:/Program%20Files/Java/jdk1.7.0_51/jre/lib/ext/sunmscapi.jar, file:/C:/Program%20Files/Java/jdk1.7.0_51/jre/lib/ext/zipfs.jar, file:/C:/Users/Vlad/IdeaProjects/blog/target/classes/, file:/C:/Users/Vlad/IdeaProjects/blog/lib/com.springsource.org.Apache.Tomcat.api-7.0.12.jar, file:/C:/Users/Vlad/IdeaProjects/blog/lib/javax.servlet-3.0.0.v201103241009.jar, file:/C:/Users/Vlad/.m2/repository/org/springframework/spring-web/4.0.0.RELEASE/spring-web-4.0.0.RELEASE.jar, file:/C:/Users/Vlad/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar, file:/C:/Users/Vlad/.m2/repository/org/springframework/spring-aop/4.0.0.RELEASE/spring-aop-4.0.0.RELEASE.jar, file:/C:/Users/Vlad/.m2/repository/org/springframework/spring-beans/4.0.0.RELEASE/spring-beans-4.0.0.RELEASE.jar, file:/C:/Users/Vlad/.m2/repository/org/springframework/spring-core/4.0.0.RELEASE/spring-core-4.0.0.RELEASE.jar, file:/C:/Users/Vlad/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar, file:/C:/Users/Vlad/.m2/repository/org/springframework/spring-context/4.0.0.RELEASE/spring-context-4.0.0.RELEASE.jar, file:/C:/Users/Vlad/.m2/repository/org/springframework/spring-expression/4.0.0.RELEASE/spring-expression-4.0.0.RELEASE.jar, file:/C:/Users/Vlad/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.0.0.BUILD-SNAPSHOT/spring-boot-autoconfigure-1.0.0.BUILD-SNAPSHOT.jar, file:/C:/Users/Vlad/.m2/repository/org/springframework/boot/spring-boot/1.0.0.BUILD-SNAPSHOT/spring-boot-1.0.0.BUILD-SNAPSHOT.jar, file:/C:/Program%20Files%20(x86)/JetBrains/IntelliJ%20IDEA%20Community%20Edition%2013.0.2/lib/idea_rt.jar]
Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.Java:136)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:476)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.Java:120)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.Java:616)
at org.springframework.boot.SpringApplication.run(SpringApplication.Java:306)
at org.springframework.boot.SpringApplication.run(SpringApplication.Java:877)
at org.springframework.boot.SpringApplication.run(SpringApplication.Java:866)
at main.Main.main(Main.Java:14)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:57)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
at Java.lang.reflect.Method.invoke(Method.Java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.Java:120)
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.Java:186)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.Java:159)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.Java:133)
... 12 more
D'après ce que je peux comprendre, il me manque un haricot? Cependant, il me semble que j'ai les haricots de printemps en pot.
Spring Boot essaie de démarrer un serveur Web, mais n’en trouve pas dans le chemin de classe. Essayez d'ajouter cette dépendance
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>I Dont know</version
</dependency>
</dependencies>
Btw you pom ne ressemble pas à un pom typique des bottes de printemps! Comparez-le avec http://projects.spring.io/spring-boot/docs/README.html
vous devez ajouter l'annotation:
@SpringBootApplication
public class Main {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Il y a des différences selon la version.
org.springframework -> S'il vous plaît corriger à une version supérieure. :)
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.5.RELEASE</version>
</dependency>
</dependencies>
Par exemple, une org.springframework.boot 1.2.3.RELEASE, erreur était toujours quand il est org.springframework 4.1.4.RELEASE ci-dessous version.
Dans le cas de plus de org.springframework 4.1.5.RELEASE, j'ai travaillé sans erreur.
J'ai eu la même erreur maintenant et je l'ai résolue en incluant simplement les mêmes versions des packages Spring dans mon fichier build.gradle:
buildscript {
ext {
springBootVersion = '1.1.6.RELEASE'
}
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-Tomcat'
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.boot:spring-boot-starter-aop'
compile 'org.springframework.boot:spring-boot-starter-data-mongodb'
Par exemple, si vous avez modifié l'un des packages et que vous ajoutez un numéro de version pour remplacer la valeur statique de 1.1.6.RELEASE, alors l'erreur s'affichera:
buildscript {
ext {
springBootVersion = '1.1.6.RELEASE'
}
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-Tomcat'
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.boot:spring-boot-starter-aop'
compile 'org.springframework.boot:spring-boot-starter-data-mongodb:1.2.5.RELEASE'
Je serais peut-être en retard à la fête, mais je pourrais peut-être épargner à quelqu'un des heures d'angoisse à la recherche de la solution.J'ai eu le même problème lors de la mise en place d'un projet Spring-Boot.
J'ai eu cela dans mon build.gradle
compile group: 'org.springframework.boot', name: 'spring-boot-starter-
web', version: '1.5.9.RELEASE'
//compile group: 'org.springframework', name: 'spring-context',
version: '5.0.2.RELEASE'// <--- Source of my problems
compile group: 'org.springframework.security.oauth', name: 'spring-
security-oauth2', version: '2.2.1.RELEASE'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-
datatype-jsr310', version: '2.9.3'
testCompile group: 'com.h2database', name: 'h2', version: '1.4.196'
compile group: 'mysql', name: 'mysql-connector-Java', version: '6.0.6'
compile group: 'org.hibernate', name: 'hibernate-core', version:
'5.2.12.Final'
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'com.google.guava', name: 'guava', version: '23.6-jre'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-
data-jpa', version: '1.5.9.RELEASE'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.springframework.boot', name: 'spring-boot-
starter-test', version: '1.5.9.RELEASE'
C'est un projet printanier et donc, il fera beaucoup de configuration pour vous
Cela dit, vous n’avez pas besoin des nombreuses dépendances que vous auriez à mettre si c’était un projet de printemps. Les boot-starter dépendances suffisent.