【发布时间】:2018-02-14 19:01:25
【问题描述】:
当尝试使用 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>
【问题讨论】:
-
你有应用程序属性文件中定义的数据源吗?
-
@RahulKargwal 我的属性文件中没有数据源,我只有:spring.mvc.view.prefix: /WEB-INF/jsp/ spring.mvc.view.suffix: .jsp 欢迎。消息:你好世界
-
这里好像还有其他文件没有贴出来,是这样吗?可能您在任何其他文件中定义了数据源或其他 bean?
标签: java spring-mvc spring-boot