java - Change the database in a Spring web app -


i have created web app spring on basis of maven archetype spring web app kolorobot on github

this archetype. since have not been developing spring several months, need help. web app using hsql db. want change db, not sure it. maybe more experience can help? content of persitence.properties file:

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 

in web app there several config classes, come along parent archetype.

this 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(); } 

}

i know spring configurable, @ minute lost.

update: when change persitence properties to:

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 

the maven package command fails. , several tests failing. in error output said: table account not found. have create tables manually or spring job?

i solved problem. changed properties to:

datasource.driverclassname=com.mysql.jdbc.driver datasource.url=jdbc:mysql://localhost:3306/mywebbapp datasource.username=root datasource.password=  hibernate.dialect=org.hibernate.dialect.mysqldialect hibernate.hbm2ddl.auto=create hibernate.connection.url=jdbc:mysql://localhost:3306/mywebbapp 

and created table named 'mywebabapp' in local mysql database.

now going setup multiple environments (test, prod, dev). let tests run against embedded h2-db user bobby zohdy suggeseted.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -