[英]Spring boot war file does not work on tomcat
我将Spring Boot添加到现有的Webapp中。 当我运行命令
java -jar -Denvironment.type=dev myfile.war
一切顺利。 但是,如果我在tomcat上部署,由于某种原因会有一个很大的例外。
Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.
我正在使用mongodb,但我的应用程序上下文中没有配置任何数据源。 我还扩展了SpringBootServletInitializer
@SpringBootApplication
public class AdminApp extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(AdminApp.class);
}
public static void main(String[] args) {
SpringApplication.run(AdminApp.class, args);
}
}
有什么线索吗?
我的属性文件
database.url=localhost
database.port=27017
database.name=dbname
database.username=admin
database.password=admin
更新:我也有此类说明应该使用哪个属性文件。
@Configuration
@PropertySource("classpath:application-${environment.type}.properties")
public class PropertyWithJavaConfig {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
在DataSourceProperties.getDriverClassName()方法中引发该错误。 在spring发行版中找到相同的源代码:
if (!StringUtils.hasText(driverClassName)) {
throw new BeanCreationException(
"Cannot determine embedded database driver class for database type "
+ this.embeddedDatabaseConnection
+ ". If you want an embedded "
+ "database please put a supported one on the classpath.");
}
当spring.datasource.driverClassName属性为空时,Spring抛出此错误。 因此,要解决此错误,请确保application.properties在类路径中。
因此,在深入研究依赖项之后,我注意到即使没有使用,我也有spring-orm和spring-jdbc。 我删除了它们,并且对于嵌入式和本地tomcat一切正常。
但是我仍然不明白为什么以前只为嵌入式tomcat工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.