我创建和春天有个web应用程序的Maven archetype for spring web app by kolorobot on GitHub在Spring Web应用程序
这个原型的基础上更改数据库。由于我没有用春季开发几个月,所以我需要一些帮助。这个网络应用程序正在使用HSQL数据库。我想改变分贝,但我不知道该在哪里做。也许有更多经验的人可以帮忙?这是我persitence.properties文件的内容:
dataSource.driverClassName=org.hsqldb.jdbcDriver
dataSource.url=jdbc:hsqldb:mem:test
dataSource.username=sa
dataSource.password=
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.hbm2ddl.auto=create
在我的web应用程序已经有几个配置类,即与父原型一起走。
这是我JPAConfig:
package org.stimpy.config;
import java.util.Properties;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.TransactionManagementConfigurer;
import org.stimpy.Application;
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackageClasses = Application.class)
class JpaConfig implements TransactionManagementConfigurer {
@Value("${dataSource.driverClassName}")
private String driver;
@Value("${dataSource.url}")
private String url;
@Value("${dataSource.username}")
private String username;
@Value("${dataSource.password}")
private String password;
@Value("${hibernate.dialect}")
private String dialect;
@Value("${hibernate.hbm2ddl.auto}")
private String hbm2ddlAuto;
@Bean
public DataSource configureDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(driver);
dataSource.setUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
return dataSource;
}
@Bean
public LocalContainerEntityManagerFactoryBean configureEntityManagerFactory() {
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(configureDataSource());
entityManagerFactoryBean.setPackagesToScan("org.stimpy");
entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
Properties jpaProperties = new Properties();
jpaProperties.put(org.hibernate.cfg.Environment.DIALECT, dialect);
jpaProperties.put(org.hibernate.cfg.Environment.HBM2DDL_AUTO, hbm2ddlAuto);
entityManagerFactoryBean.setJpaProperties(jpaProperties);
return entityManagerFactoryBean;
}
@Bean
public PlatformTransactionManager annotationDrivenTransactionManager() {
return new JpaTransactionManager();
}
}
我知道春天是非常可配置的,但在一分钟我迷路了。
更新: 当我改变persitence性质:
dataSource.driverClassName=org.h2.Driver
dataSource.url=jdbc:h2:mem:test
dataSource.username=sa
dataSource.password=
hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.hbm2ddl.auto=create
行家包命令失败。几项测试都失败了。在错误输出中,它表示: 未找到表ACCOUNT。我是否必须手动创建表或Spring是否完成这项工作?
刚刚在引用的persitence.properties中更改数据库时发生了什么? –
这些是需要更改的属性,以及更改它们时发生了什么,您可以发布错误消息/问题吗?还有什么是新的数据库,甲骨文,MySql等 –
我想使用h2数据库像用户地理和suggestesttest。但现在9个测试中有7个失败。我编辑了我的问题。 –