Skip to content

Instantly share code, notes, and snippets.

@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>
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
Session session = sessionFactory
.withOptions()
.tenantIdentifier(yourTenantIdentifier)
...
.openSession();
@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;
@jose-mgmaestre
jose-mgmaestre / CurrentTenantIdentifierResolverImpl.java
Last active January 17, 2018 14:01
Multitenancy junit test : Using a global tenant
/**
* It specify what Tenant should be used:
* <p>
* <p>
* There are 2 modes of resolving the identifier using {@link #resolveCurrentTenantIdentifier()}:
*
* <li> Using a global tenant identifier for junit testing
* <li> Using the http session to get the tenant for deployed applications
*
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:META-INF/spring/testContext.xml" })
@DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD)
public class MultiTenantConnectionProviderTest {
...
@Autowired
MultiTenantConnectionProviderImpl multitenancyConnectionProvider;
@jose-mgmaestre
jose-mgmaestre / Body.java
Created April 13, 2018 15:25
Body as simple as possible to explain the injection
package com.ricston.injectionexample.domain;
import com.ricston.injectionexample.domain.com.ricston.injectionexample.domain.blood.Blood;
import javax.inject.Inject;
public class Body {
@Inject
public Body(){}