EzyJPA: Configuration
Updated at 16856874240001. Configuration List
EzyJPA provides a list of configurations in bellow table:Property | Default Value | Description | |
1 | datasource.jdbc_url | null | JDBC connection url |
2 | datasource.username | null | Datasource's username |
3 | datasource.password | null | Datasource's password |
4 | datasource.driver_class_name | null | JDBC driver class name |
5 | datasource.database_name | null | Database name |
You can encrypt sensitive configuration like username, password if you want and please take a look HikariCP to find out another configuration.
2. An Example
You can put bellow configuration to your application.yaml
file:
# for application.yaml datasource: jdbcUrl: jdbc:mysql://root:12345678@localhost:3306/test driverClassName: com.mysql.cj.jdbc.Driver
Or for application.properties
file:
# for application.properties datasource.jdbcUrl=jdbc:mysql://root:12345678@localhost:3306/test datasource.driverClassName=com.mysql.cj.jdbc.Driver
3. Auto Configuration
To configure automatically, you just need add configuration and add ezyfox-boot-autoconfigure
to your project dependency like this:
4. Configure Manually
For some reason, you can not use ezyfox-boot-autoconfigure
you can config like this:
import com.tvd12.ezydata.database.EzyDatabaseContext; import com.tvd12.ezydata.jpa.EzyJpaDatabaseContextBuilder; import com.tvd12.ezydata.jpa.loader.EzyJpaDataSourceLoader; import com.tvd12.ezydata.jpa.loader.EzyJpaEntityManagerFactoryLoader; import com.tvd12.ezyfox.bean.EzyBeanConfig; import com.tvd12.ezyfox.bean.EzyPackagesToScanAware; import com.tvd12.ezyfox.bean.EzySingletonFactory; import com.tvd12.ezyfox.bean.EzySingletonFactoryAware; import com.tvd12.ezyfox.bean.annotation.EzyAutoBind; import com.tvd12.ezyfox.bean.annotation.EzyConfigurationBefore; import com.tvd12.ezyfox.util.EzyPropertiesAware; import lombok.Setter; import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; import java.util.Properties; import java.util.Set; import static com.tvd12.ezyfox.boot.util.EzyDatabaseContexts.addRepositoriesFromDatabaseContextToSingletonFactory; @Setter @EzyConfigurationBefore public class EzyJpaConfiguration implements EzyBeanConfig, EzyPropertiesAware, EzySingletonFactoryAware { private Properties properties; @EzyAutoBind private EzySingletonFactory singletonFactory; @Override public void config() { addRepositoriesFromDatabaseContextToSingletonFactory( databaseContext(), singletonFactory ); } private EzyDatabaseContext databaseContext() { return new EzyJpaDatabaseContextBuilder() .properties(properties) .entityManagerFactory(entityManagerFactory()) .scan("your_package_to_scan") .build(); } private EntityManagerFactory entityManagerFactory() { return new EzyJpaEntityManagerFactoryLoader() .entityPackages(packagesToScan) .dataSource(dataSource()) .properties(properties) .load("Default"); } private DataSource dataSource() { return new EzyJpaDataSourceLoader() .properties(properties, "datasource") .load(); } }
Next
You can take a look a list of default functions.