Eclipse Spring Boot搭建中的问题

1. The type javax.servlet.ServletContext cannot be resolved

    原因默认生成的pom.xml

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
			<scope>provided</scope>
		</dependency>
    下面这个属性,表示使用本机已经存在的东西,不会下载对应的东西。
<scope>provided</scope>

    解决:eclipse里添加本机的tomcat server,然后在项目的Java Build Path->Libraries->Add Library->Server Runtime添加server的库。


2. 启动服务时,出现下面的错:

     ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).

这是因为spring boot默认会加载org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration类,DataSourceAutoConfiguration类使用了@Configuration注解向spring注入了dataSource bean。因为工程中没有关于dataSource相关的配置信息,当spring创建dataSource bean因缺少相关的信息就会报错。
因为我仅仅只是使用spring boot来写一些很简单的例子来学习它,在Application类上增加@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
阻止spring boot自动注入dataSource bean
    

猜你喜欢

转载自blog.csdn.net/langzitianya/article/details/79128927