gpt4 book ai didi

java - Spring 启动 : Unable to configure

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:22:24 25 4
gpt4 key购买 nike

似乎(也许不是),SpringBoot 无法加载驻留在 src/main/resources 上的 application.properties 文件。我需要添加什么额外的配置来启动我的应用程序?

错误跟踪:

原因:

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).

MembersApplication.java

@SpringBootApplication
public class MembersApplication {

public static void main(String[] args)
{
SpringApplication.run(MembersApplication.class, args);
}
}

DatabaseConfig.java

@Configuration
@EnableTransactionManagement
public class DatabaseConfig {

@Value("${db.driver}")
private String DB_DRIVER;

@Value("${db.password}")
private String DB_PASSWORD;

@Value("${db.url}")
private String DB_URL;

@Value("${db.username}")
private String DB_USERNAME;

@Value("${hibernate.dialect}")
private String HIBERNATE_DIALECT;

@Value("${hibernate.show_sql}")
private String HIBERNATE_SHOW_SQL;

@Value("${hibernate.hbm2ddl.auto}")
private String HIBERNATE_HBM2DDL_AUTO;

@Value("${entitymanager.packagesToScan}")
private String ENTITYMANAGER_PACKAGES_TO_SCAN;

@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(DB_DRIVER);
dataSource.setUrl(DB_URL);
dataSource.setUsername(DB_USERNAME);
dataSource.setPassword(DB_PASSWORD);
return dataSource;
}

@Bean
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean();
sessionFactoryBean.setDataSource(dataSource());
sessionFactoryBean.setPackagesToScan(ENTITYMANAGER_PACKAGES_TO_SCAN);
Properties hibernateProperties = new Properties();
hibernateProperties.put("hibernate.dialect", HIBERNATE_DIALECT);
hibernateProperties.put("hibernate.show_sql", HIBERNATE_SHOW_SQL);
hibernateProperties.put("hibernate.hbm2ddl.auto", HIBERNATE_HBM2DDL_AUTO);
sessionFactoryBean.setHibernateProperties(hibernateProperties);

return sessionFactoryBean;
}

@Bean
public HibernateTransactionManager transactionManager() {
HibernateTransactionManager transactionManager =
new HibernateTransactionManager();
transactionManager.setSessionFactory(sessionFactory().getObject());
return transactionManager;
}

最佳答案

您的类路径中缺少 DB JAR。如果您使用的是 Maven/Gradle,只需将 JDBC 驱动程序依赖项包含到您的 POM/gradle 文件中即可。

关于java - Spring 启动 : Unable to configure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33982811/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com