import java.util.LinkedList; import java.util.List; import org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo; import org.springframework.orm.jpa.persistenceunit.PersistenceUnitPostProcessor; public class DemoPersistenceUnitPostProcessor implements PersistenceUnitPostProcessor { private List<String> mappingFileNames = new LinkedList<String>(); public void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo pui) { if(pui != null){ List<String> fileNames = pui.getMappingFileNames(); fileNames.addAll(mappingFileNames); } } public List<String> getMappingFileNames() { return mappingFileNames; } public void setMappingFileNames(List<String> mappingFileNames) { this.mappingFileNames = mappingFileNames; } }
#local
db.url=jdbc:oracle:thin:@xx.com:1538:dbName
db.username=test
db.password=test
#spring integration
channel.default.timeout=5000
# MQ
mq.host.name=xx.com
mq.host.port=1420
mq.channel=aa
mq.queue.manager=bb
mq.queue.name.sender=cc
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd "> <aop:aspectj-autoproxy /> <bean id="placeholderProperties" class="com.xx.spring.EncryptedPropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath*:common.properties</value> <value>classpath*:app.properties</value> </list> </property> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> <property name="ignoreUnresolvablePlaceholders" value="true" /> <property name="order" value="1" /> <property name="encryptPropertyNames"> <list> <value>db.password</value> </list> </property> </bean> <jpa:repositories base-package="com.xx" /> <context:component-scan base-package="com.xx" /> <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" /> <import resource="ds/beans-tx.xml" /> <import resource="ds/beans-db-source.xml" /> <import resource="ds/beans-mq-source.xml" /> <import resource="classpath*:/beans.xml" /> </beans>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration" xmlns:int-jpa="http://www.springframework.org/schema/integration/jpa" xmlns:int-jms="http://www.springframework.org/schema/integration/jms" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:stream="http://www.springframework.org/schema/integration/stream" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd http://www.springframework.org/schema/integration/jpa http://www.springframework.org/schema/integration/jpa/spring-integration-jpa.xsd"> <!-- Declare a transaction manager --> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="emf" /> <property name="dataSource" ref="dataSource" /> </bean> <tx:annotation-driven/> <!-- JMS manager --> <bean id="JmsTxManager" class="org.springframework.jms.connection.JmsTransactionManager"> <property name="connectionFactory" ref="cacheConnectionFactory" /> </bean> </beans>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns:int="http://www.springframework.org/schema/integration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:int-stream="http://www.springframework.org/schema/integration/stream" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd"> <!-- cache connection factory --> <bean id="cacheConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"> <property name="targetConnectionFactory" ref="connectionFactory" /> <property name="sessionCacheSize" value="15" /> <property name="cacheProducers" value="false" /> </bean> <!-- raw connection factory --> <bean name="obdConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory"> <property name="channel" value="${mq.channel}" /> <property name="hostName" value="${mq.server}" /> <property name="port" value="${mq.port}" /> <property name="queueManager" value="${mq.manager}" /> <property name="transportType" value="1" /> </bean> <bean id="JmsTemplate" class="org.springframework.jms.core.JmsTemplate"> <property name="connectionFactory" ref="cacheConnectionFactory" /> <property name="defaultDestinationName" value="${mq.queue}" /> <property name="messageConverter" ref="messageConverter" /> <property name="pubSubDomain" value="false" /> <property name="explicitQosEnabled" value="true" /> <property name="deliveryMode" value="2" /> </bean> <bean id="messageConverter" class="org.springframework.jms.support.converter.SimpleMessageConverter" /> </beans>
<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd "> <persistence-unit name="abc.unit"> <properties> <property name="hibernate.show_sql" value="false" /> <property name="hibernate.hbm2ddl.auto" value="validate" /> </properties> </persistence-unit> </persistence>
import java.io.IOException; import java.util.Date; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.transaction.TransactionConfiguration; import org.springframework.transaction.annotation.Transactional; @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true) @Transactional @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:context.xml") public class LogDetailTest { @Autowired private LogDetailRepository repository; private LogDetail logDetail; private final String STATUS = "100"; @Before public void setUp() throws IOException { } @Test public void insertSuccessfully() { } }