Skip to content

Instantly share code, notes, and snippets.

@PropertySource("classpath:/com/myco/app.properties")
@Configuration
public class ApplicationConfig {
@Autowired
Environment env;
//...
@Bean
/**
* It lookup the correct datasource to use, we have one per tenant
*
* The tenant datasource has default properties from database.properties and
* also properties in database.{tenantId}.properties whose properties override
* the default ones.
*
* @author jose.mgmaestre
*
*/
/**
* It specify what Tenant should be use when the hibernate session is created.
* @author jm
*/
public class CurrentTenantIdentifierResolverImpl implements CurrentTenantIdentifierResolver {
Logger logger = Logger.getLogger(getClass());
@Override
/**
* It gets the connection based on different datasources.
*/
public class MultiTenantConnectionProviderImpl extends AbstractDataSourceBasedMultiTenantConnectionProviderImpl
{
Log logger = LogFactory.getLog(getClass());
private static final long serialVersionUID = 14535345L;
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
id="entityManagerFactory">
<property name="persistenceUnitManager" ref="pum"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="${database.dialect}" />
</bean>
</property>
<property name="jpaPropertyMap">
Session session = sessionFactory
.withOptions()
.tenantIdentifier(yourTenantIdentifier)
...
.openSession();
Dependency convergence error for log4j:log4j:1.2.17 paths to dependency are:
+-com.ricston.conflict:conflict-info:2.1.3-SNAPSHOT
+-org.slf4j:slf4j-log4j12:1.7.6
+-log4j:log4j:1.2.17
and
+-com.ricston.conflict:conflict-info:2.1.3-SNAPSHOT
+-log4j:log4j:1.2.16
@jose-mgmaestre
jose-mgmaestre / pom.xml
Created September 12, 2016 14:35
Enforcer plugin configured in pom
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<configuration>
<rules><dependencyConvergence/></rules>
</configuration>
</plugin>
</plugins>