gpt4 book ai didi

mysql - 如何在 Bluemix 上为 MySQL 配置云数据源?

转载 作者:行者123 更新时间:2023-11-29 20:27:52 28 4
gpt4 key购买 nike

在 Bluemix 上运行时,如何在 MySQL 中创建云数据源?如果有可用的Java配置示例,请分享。如何让 Hibernate 创建表以及为什么会出现此错误?

Error creating bean with name 'entityManagerFactory' defined in com.covenant.app.config.root.DatabaseConfig: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.jdbc.datasource.DriverManagerDataSource]: : No qualifying bean of type [org.springframework.jdbc.datasource.DriverManagerDataSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.datasource.DriverManagerDataSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

我的数据库配置类

@Configuration
@Profile("cloud")
@EnableTransactionManagement
public class CloudDatabaseConfig extends AbstractCloudConfig {

@Bean
public DataSource inventoryDataSource() {
return connectionFactory().dataSource("mysql");
}
@Bean(name = "namingStrategy")
public ImprovedNamingStrategy getNamingStrategy(){

ImprovedNamingStrategy namingStrategy = new CDCustomNamingStrategy();
return namingStrategy;
}
@Bean(name="dataSource")
public BasicDataSource dataSource() throws PropertyVetoException {
BasicDataSource bean = new BasicDataSource();
bean.setDriverClassName("com.mysql.jdbc.Driver");
bean.setUrl("jdbc:mysql://localhost:3306/bluemix?useUnicode=true&characterEncoding=UTF-8");
bean.setUsername("root");
bean.setPassword("root");
return bean;
}
@Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, ImprovedNamingStrategy ins) {

LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(dataSource);
entityManagerFactoryBean.setPackagesToScan(new String[]{"com.covenant.app.model"});
entityManagerFactoryBean.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());


Map<String, Object> jpaProperties = new HashMap<String, Object>();
jpaProperties.put("database", "mysql");
jpaProperties.put("hibernate.hbm2ddl.auto", "update");
jpaProperties.put("hibernate.show_sql", "true");
jpaProperties.put("hibernate.format_sql", "true");
jpaProperties.put("hibernate.use_sql_comments", "true");
jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
jpaProperties.put("hibernate.ejb.naming_strategy", ins);
entityManagerFactoryBean.setJpaPropertyMap(jpaProperties);

return entityManagerFactoryBean;
}

}

我在 Bluemix 上的 manifest.yml 文件:

---
applications:
- name: lordthankyou
path: target/ideals.war
services:
- mysql
env:
SPRING_PROFILES_ACTIVE: cloud

我收到以下错误:

Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.covenant.app.dao.UserRepository com.covenant.app.services.UserService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined

最佳答案

终于我开始工作了,我刚刚添加了一个环境变量来激活manifest.yml中的云配置文件,并删除了扩展AbstractCloudConfig,因为它也在搜索mongodb。在这些更改之后,它开始工作,现在我可以在blue mix上运行spring mvc .

关于mysql - 如何在 Bluemix 上为 MySQL 配置云数据源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39190791/

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