View EntityCreatedEventListener.java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
@Component
public class EntityCreatedEventListener implements ApplicationListener<EntityCreatedEvent> {
@Autowired
private EmailService emailService;
View EntityCreatedEvent.java
import org.springframework.context.ApplicationEvent;
public class EntityCreatedEvent<T> extends ApplicationEvent {
private T entity;
public EntityCreatedEvent(Object source, T entity) {
super(source);
this.entity = entity;
}
View ProjectServiceImpl.java
@Service
public class ProjectServiceImpl implements ProjectService {
@Autowired
private ApplicationEventPublisher applicationEventPublisher;
@Override
public void createProject(Project project) {
// save project entity in the database and publish an event to send mail to project owner
publishProjectCreatedEvent(project);
View Project.java
package xyz.jeevan.api.domain;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* Projects mongo document.
*/
@Document(collection = "projects")
public class Project {
View hikaricp-config.xml
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<property name="poolName" value="mercatus_connection_pool" />
<property name="dataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"/>
<property name="maximumPoolSize" value="50" />
<property name="maxLifetime" value="60000" />
<property name="idleTimeout" value="30000" />
<property name="dataSourceProperties">
<props>
<prop key="url">${jdbc.url}</prop>
<prop key="user">${jdbc.username}</prop>
View hikaricp-dependency.xml
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP-java7</artifactId>
<version>2.4.12</version>
</dependency>
View c3p0-depencency.xml
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
View c3p0-config.xml
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driverClassName}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="minPoolSize" value="10"/>
<property name="maxPoolSize" value="50"/>
<property name="acquireIncrement" value="1"/>
<property name="idleConnectionTestPeriod" value="1000"/>
<property name="maxStatements" value="250"/>
View dbcp2-pool-config.xml
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="initialSize" value="10" />
<property name="maxTotal" value="50" />
</bean>
View dbcp2-dependency.xml
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.1.1</version>
</dependency>