Skip to content

Commit

Permalink
add infrastrctrue
Browse files Browse the repository at this point in the history
  • Loading branch information
Percy0601 committed May 28, 2015
1 parent 1a53247 commit 00fc800
Show file tree
Hide file tree
Showing 25 changed files with 573 additions and 24 deletions.
2 changes: 2 additions & 0 deletions boot-dubbo-infrastructure/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target/
/target/
64 changes: 64 additions & 0 deletions boot-dubbo-infrastructure/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.creditease</groupId>
<artifactId>boot-dubbo</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>boot-dubbo-infrastructure</artifactId>
<name>boot-dubbo-infrastructure</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.7</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>3.6.4</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>true</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package boot.dubbo.infrastructure;

import java.io.IOException;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class ApplicationBootstrap {

public static void main(String[] args) {
SpringApplication.run(ApplicationBootstrap.class, args);
try {
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package boot.dubbo.infrastructure.config;

import javax.sql.DataSource;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperFactoryBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import boot.dubbo.infrastructure.repo.ComplexQueryRepo;

@Configuration
@ConfigurationProperties(prefix = "mybatis", ignoreUnknownFields = false)
public class MyBatisConfig {
private Logger log = LoggerFactory.getLogger(MyBatisConfig.class);

private String configLocationXml = "MyBatis-Configuration.xml";

public String getConfigLocationXml() {
return configLocationXml;
}

public void setConfigLocationXml(String configLocationXml) {
this.configLocationXml = configLocationXml;
}

@Bean
@Autowired
public SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource) {
log.info("加载MyBatis配置文件:{}", configLocationXml);
Resource configLocation = new ClassPathResource(configLocationXml);
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setConfigLocation(configLocation);
sqlSessionFactoryBean.setDataSource(dataSource);
return sqlSessionFactoryBean;
}

@Bean
@Autowired
public ComplexQueryRepo apiServiceMapperFactoryBean(
SqlSessionFactoryBean sqlSessionFactory) throws Exception {
MapperFactoryBean<ComplexQueryRepo> mapperFactoryBean = new MapperFactoryBean<ComplexQueryRepo>();
mapperFactoryBean.setMapperInterface(ComplexQueryRepo.class);
mapperFactoryBean.setSqlSessionFactory(sqlSessionFactory.getObject());
return mapperFactoryBean.getObject();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package boot.dubbo.infrastructure.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "boot_user")
public class User {

private Integer id;
private String username;
private String password;

@Id
@GeneratedValue
public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

@Column
public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

@Column
public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package boot.dubbo.infrastructure.repo;

import java.util.List;

import boot.dubbo.infrastructure.entity.User;

/**
* 综合复杂查询<br>
*
*
* @author percy
*
*/
public interface ComplexQueryRepo {

List<User> findUsersLike(String name);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package boot.dubbo.infrastructure.repo;

import org.springframework.data.jpa.repository.JpaRepository;

import boot.dubbo.infrastructure.entity.User;

public interface UserRepo extends JpaRepository<User, Integer> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Java 规范配置文件
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# DataSource Config
spring.datasource.url=jdbc:h2:~/h2/uaas/test;MODE=PostgreSQL;LOCK_MODE=3
spring.datasource.username=sa
spring.datasource.password=123456
spring.datasource.driver-class-name=org.h2.Driver

# JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming_strategy= org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.database=H2
spring.jpa.show-sql=true
# MyBatis Config
mybatis.configLocationXml=mybatis/MyBatis-Configuration.xml
30 changes: 30 additions & 0 deletions boot-dubbo-infrastructure/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<contextName>UAAS-CONSOLE</contextName>

<include resource="org/springframework/boot/logging/logback/base.xml" />
<!-- include resource="org/springframework/boot/logging/logback/console-appender.xml"
/> -->

<!-- <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern> %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender> -->


<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>

<!-- logback为java中的包 -->
<logger name="uaas" />

<!--logback.LogbackDemo:类的全路径 -->
<logger name="uaas.controller.RoleController" level="DEBUG"
additivity="false">
<appender-ref ref="CONSOLE" />
</logger>

</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="boot.dubbo.infrastructure.repo.ComplexQueryRepo">

<select id="findUsersLike" parameterType="String"
resultType="boot.dubbo.infrastructure.entity.User">
select id "id", username "username" from boot_user
</select>

</mapper>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>

<settings>
<setting name="cacheEnabled" value="true" />
<setting name="lazyLoadingEnabled" value="false" />
<setting name="aggressiveLazyLoading" value="true" />
<setting name="logImpl" value="LOG4J" />
</settings>

<plugins>
<!-- com.github.pagehelper为PageHelper类所在包名 -->
<plugin interceptor="com.github.pagehelper.PageHelper">

<property name="dialect" value="postgresql" />

<!-- 该参数默认为false -->
<!-- 设置为true时,会将RowBounds第一个参数offset当成pageNum页码使用 -->
<!-- 和startPage中的pageNum效果一样 -->
<property name="offsetAsPageNum" value="true" />

<!-- 该参数默认为false -->
<!-- 设置为true时,使用RowBounds分页会进行count查询 -->
<property name="rowBoundsWithCount" value="true" />

<!-- 设置为true时,如果pageSize=0或者RowBounds.limit = 0就会查询出全部的结果 -->
<!-- (相当于没有执行分页查询,但是返回结果仍然是Page类型) -->
<property name="pageSizeZero" value="true" />

<!-- 3.3.0版本可用 - 分页参数合理化,默认false禁用 -->
<!-- 启用合理化时,如果pageNum<1会查询第一页,如果pageNum>pages会查询最后一页 -->
<!-- 禁用合理化时,如果pageNum<1或pageNum>pages会返回空数据 -->
<property name="reasonable" value="true" />

<!-- 3.5.0版本可用 - 为了支持startPage(Object params)方法 -->
<!-- 增加了一个`params`参数来配置参数映射,用于从Map或ServletRequest中取值 -->
<!-- 可以配置pageNum,pageSize,count,pageSizeZero,reasonable,不配置映射的用默认值 -->
<!-- 不理解该含义的前提下,不要随便复制该配置 -->
<property name="params" value="pageNum=start;pageSize=limit;" />

</plugin>
</plugins>
<mappers>
<mapper resource="mybatis/ApiServiceRepoMapper.xml" />
</mappers>

</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package boot.dubbo.infrastructure;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}

/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}

/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}
Loading

0 comments on commit 00fc800

Please sign in to comment.