`

spring data demo part 2

 
阅读更多
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() {

    }

}



分享到:
评论

相关推荐

    springmvc文件上传Demo

    2. **后端配置**:在Spring MVC的配置文件中,我们需要添加MultipartResolver bean来处理多部分请求。通常使用`CommonsMultipartResolver`,它依赖于Commons FileUpload库。 3. **控制器方法**:在控制器类中,创建...

    SpringMVC文件上传Demo代码

    &lt;bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt; &lt;!-- 指定最大上传文件大小 --&gt; ``` 接着,我们需要创建一个控制器(Controller)类,该类将处理...

    springMVC文件上传demo(亲测有效)

    &lt;bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt; &lt;!-- 设置最大上传文件大小,单位为MB --&gt; ``` 其中,`maxUploadSize`属性用来限制上传文件的...

    springboot文件上传demo

    本示例“springboot文件上传demo”旨在演示如何在Spring Boot应用中实现这一功能。我们将探讨以下关键知识点: 1. **Maven依赖管理**: 文件上传涉及的依赖主要是`spring-boot-starter-web`,它包含了处理HTTP请求...

    文件上传demo

    &lt;bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt; &lt;property name="maxUploadSize" value="10485760"/&gt; &lt;!-- 10MB --&gt; ``` 在控制器层,我们可以创建...

    ssm整合Demo源文件_支持多文件上传.zip

    在`web.xml`中,我们需要设置`multipartResolver`,通常使用的是`CommonsMultipartResolver`,这是Spring对Apache Commons FileUpload库的封装。配置完成后,Spring MVC就能处理`multipart/form-data`类型的POST请求...

    springmvc学习demo

    Spring MVC 可以配合分页库,如 MyBatis 的 PageHelper 或 Spring Data JPA 的 Pageable 接口,实现高效的分页查询。这使得用户能够逐步加载和浏览大量结果,提高应用性能。 5. **文件上传**:Spring MVC 提供了 ...

    ssm整合Demo源文件_添加上传功能

    首先,我们需要在Spring MVC的配置文件中开启MultipartResolver,这是处理multipart/form-data类型的表单数据,也就是文件上传的关键。这可以通过添加`&lt;bean&gt;`标签来实现,使用`CommonsMultipartResolver`类: ```...

    uploadifive SpringMVC文件上传Demo

    &lt;bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt; &lt;property name="maxUploadSize" value="10485760" /&gt; &lt;!-- 设置最大上传文件大小,这里是10MB --&gt; ...

    文件的上传与下载demo

    5. **框架支持**:在实际开发中,可能会使用Spring MVC或Struts2等框架,它们提供了更高级的文件上传和下载支持,简化了代码编写。 6. **用户体验**:在前端,可以使用HTML5的`&lt;input type="file"&gt;`元素和...

    微信支付javaSpringboot对接开发微信支付

    - 参考官方文档完成各项配置:[微信支付官方文档](https://pay.weixin.qq.com/wiki/doc/apiv3/open/pay/chapter2_8_1.shtml#part-1)。 #### 二、开发环境准备 1. **开发环境**: - **开发语言**:Java - **编译...

    springMVCwebUploader文件上传

    对于"图片上传DEMO"和"图片上传简单实现"这两个标签,我们可以理解为涉及图片的上传示例。在实际应用中,除了基本的文件上传,可能还会涉及到图片的预览、缩略图生成、格式转换、大小限制等操作。例如,我们可以使用...

    springmvcfileupload.rar

    &lt;bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt; &lt;!-- one of the properties available; the maximum file size in bytes --&gt; ...

    fileinputdemo

    在Java中,可以使用Apache Commons FileUpload库或者Java内置的Part接口来解析上传的文件。以下是一个简单的Servlet示例: ```java @WebServlet("/uploadServlet") public class UploadServlet extends HttpServlet ...

    java实现文件上传下载D的JAR

    &lt;bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt; &lt;property name="maxUploadSize" value="10485760"/&gt; &lt;!-- 设置最大上传文件大小,这里是10MB --&gt; ...

    SSH 完整框架(包括数据库部分)

    SSH,全称Spring、Struts、Hibernate,是Java Web开发中的三大开源框架,它们分别负责应用的业务逻辑层(Spring)、视图展示层(Struts)以及数据持久化层(Hibernate)。这个“SSH 完整框架(包括数据库部分)”应该...

    上传照片 java例子

    除了Servlet API,还有一些库如Apache Commons FileUpload和Spring MVC的`MultipartFile`接口,它们提供了更高级的文件上传处理功能,如流式处理大文件,但本例中没有使用。 在"friend_demo"这个项目中,可能包含了...

    JAVA_servlet的文件上传案例

    同时,使用框架如Spring MVC或Struts2可以简化文件上传的实现,提供更丰富的功能和错误处理机制。 总之,文件上传是Java Web开发中的常见需求,通过Servlet API,我们可以轻松实现这一功能。这个"JAVA_servlet的...

    springMVC多图片上传示例

    &lt;bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt; &lt;!-- 设置最大上传文件大小,单位为MB --&gt; ``` 4. **编写控制器** 创建一个处理文件上传的...

    fileUpload_20130819

    尽管作者自谦代码写得不好,但这个demo仍然为我们提供了一些关键知识点,可以帮助我们理解图片上传的基本流程。 首先,我们要知道的是Java EE中的Multipart请求处理。在用户通过表单上传图片时,服务器端需要解析...

Global site tag (gtag.js) - Google Analytics