当尝试使用springBoot和Tomcat Embeded运行我的第一个HelloWorld应用程序时,我得到以下异常:
org.springframework.beans.factory.BeanDefinitionStoreException:失败 读取候选组件类嵌套异常是 java.lang.IllegalStateException:无法评估org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration $ EmbeddedDatabaseConfiguration上的条件 由于未找到org / springframework / dao / DataAccessException。使 确保您自己的配置不依赖于该类。这也可以 如果您是@ComponentScanning springframework包(例如, 如果你错误地将@ComponentScan放在默认包中
这是我的入口点示例类配置:
@SpringBootApplication
public class Example extends SpringBootServletInitializer
{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application)
{
return application.sources(Example.class);
}
public static void main(String[] args) throws Exception
{
SpringApplication.run(Example.class, args);
}
}
这是我的WelcomeController类:
package controler;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Map;
@Controller
public class WelcomeController
{
// inject via application.properties
@Value("${welcome.message:test}")
private String message = "Hello World";
@RequestMapping("/")
public String welcome(Map<String, Object> model)
{
model.put("message", this.message);
return "welcome";
}
}
这是我的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.springBoot</groupId>
<artifactId>SpringbootHelloword</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Tomcat embedded container-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- JSTL for JSP -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- Need this to compile JSP -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- Need this to compile JSP,
tomcat-embed-jasper version is not working, no idea why -->
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>4.6.1</version>
<scope>provided</scope>
</dependency>
<!-- Optional, test for static content, bootstrap CSS-->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
</dependencies>
</project>
答案 0 :(得分:0)
我更改了服务器端口,因为它被另一个应用程序使用并且它可以正常工作。