Commit 6824bdd8 by ethanlamzs

1、sharding-jdbc的编排治理功能配置beta

2、同时配置启用两个事例提供者服务 与 一个消费者对应
1 parent 8ccacceb
Showing 63 changed files with 1437 additions and 110 deletions
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>fpj-xcx</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>common-base</artifactId>
<name>common-base</name>
<description>项目的公有组件类</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.2</version>
<configuration>
<aggregate>true</aggregate>
<tags>
<tag>
<name>Description</name>
<placement>a</placement>
<head>用途</head>
</tag>
</tags>
<reportOutputDirectory>target/report_output</reportOutputDirectory>
<destDir>target/apidocs</destDir>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file \ No newline at end of file
package com.zhzf.fpj.xcx.demodubbospringbootstart;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoDubboSpringBootStartApplication {
public static void main(String[] args) {
SpringApplication.run(DemoDubboSpringBootStartApplication.class, args);
}
}
package com.zhzf.fpj.xcx.demodubbospringbootstart;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class DemoDubboSpringBootStartApplicationTests {
@Test
public void contextLoads() {
}
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>fpj-xcx</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>common-fk-base</artifactId>
<name>common-fk-base</name>
<description>项目的框架扩展类</description>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>1.5.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.2</version>
<configuration>
<aggregate>true</aggregate>
<tags>
<tag>
<name>Description</name>
<placement>a</placement>
<head>用途</head>
</tag>
</tags>
<reportOutputDirectory>target/report_output</reportOutputDirectory>
<destDir>target/apidocs</destDir>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file \ No newline at end of file
package com.zhzf.fpj.xcx.envir;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.PropertySource;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
/**
*
*/
public class ApplicationEnvironmentPreparedEventListener
implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
private Logger logger = LoggerFactory.getLogger(ApplicationEnvironmentPreparedEventListener.class);
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
logger.info("ApplicationEnvironmentPreparedEventListener.....onApplicationEvent start");
ConfigurableEnvironment envi = event.getEnvironment();
MutablePropertySources mps = envi.getPropertySources();
Properties properties = new Properties();
properties.put("mysql.host.info","115.28.171.4:3306");
PropertiesPropertySource ex_pro = new PropertiesPropertySource("startup",properties);
mps.addFirst(ex_pro);
envi.resolvePlaceholders("${mysql.host.info}");
if (mps != null) {
Iterator<PropertySource<?>> iter = mps.iterator();
while (iter.hasNext()) {
PropertySource<?> ps = iter.next();
logger.info("===> ps.getName:{};ps.getSource:{};ps.getClass:{}", ps.getName(), ps.getSource(), ps.getClass());
}
}
logger.info("ApplicationEnvironmentPreparedEventListener.....onApplicationEvent end");
}
}
\ No newline at end of file \ No newline at end of file
package com.zhzf.fpj.xcx.envir;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import java.util.Iterator;
public class ApplicationListener2 implements ApplicationListener<ApplicationPreparedEvent> {
private Logger logger = LoggerFactory.getLogger(ApplicationListener2.class);
public void onApplicationEvent(ApplicationPreparedEvent event){
logger.info("onApplicationEvent.....onApplicationEvent start");
ConfigurableEnvironment envi = event.getApplicationContext().getEnvironment();
MutablePropertySources mps = envi.getPropertySources();
//PropertiesPropertySource ex_pro = new PropertiesPropertySource();
if (mps != null) {
Iterator<PropertySource<?>> iter = mps.iterator();
while (iter.hasNext()) {
PropertySource<?> ps = iter.next();
logger.info("===> ps.getName:{};ps.getSource:{};ps.getClass:{}", ps.getName(), ps.getSource(), ps.getClass());
}
}
logger.info("onApplicationEvent.....onApplicationEvent end");
}
}
...@@ -10,6 +10,15 @@ ...@@ -10,6 +10,15 @@
<name>core-api</name> <name>core-api</name>
<description>core-api</description> <description>core-api</description>
<dependencies>
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>core-common-beans</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
......
package com.zhzf.fpj.xcx.demo; package com.zhzf.fpj.xcx.api.demo;
public interface DemoService { public interface DemoService {
......
package com.zhzf.fpj.xcx.api.demo;
public interface DemoServiceOther {
String sayHelloOther(String name);
}
\ No newline at end of file \ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>core-buiness-demo-sec</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>buiness-dao-demo-sec</artifactId>
<name>buiness-dao-demo-sec</name>
<description>buiness-dao-demo-sec</description>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>io.shardingjdbc</groupId>
<artifactId>sharding-jdbc-orchestration-spring-boot-starter</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file \ No newline at end of file
/*
* Copyright 1999-2015 dangdang.com.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* </p>
*/
package com.zhzf.fpj.xcx.demo.mybatis;
import com.zhzf.fpj.xcx.demo.mybatis.service.DemoService;
import com.zhzf.fpj.xcx.envir.ApplicationEnvironmentPreparedEventListener;
import com.zhzf.fpj.xcx.envir.ApplicationListener2;
import io.shardingjdbc.orchestration.api.util.OrchestrationDataSourceCloseableUtil;
import io.shardingjdbc.orchestration.internal.OrchestrationShardingDataSource;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
@SpringBootApplication
public class SpringBootDataMybatisMain {
// CHECKSTYLE:OFF
public static void main(final String[] args) {
// CHECKSTYLE:ON
// ApplicationContext applicationContext = SpringApplication.run(SpringBootDataMybatisMain.class, args);
// applicationContext.getBean(DemoService.class).demo();
Object[] starts = new Object[1];
starts[0] = SpringBootDataMybatisMain.class;
SpringApplication app = new SpringApplication(starts);
//app.addListeners(new ApplicationEnvironmentPreparedEventListener());
//app.addListeners(new ApplicationListener2());
ApplicationContext applicationContext = app.run(args);
//applicationContext.getBean(DemoService.class).demo("local_dao-demo-sec");
//OrchestrationDataSourceCloseableUtil.closeQuietly(applicationContext.getBean(OrchestrationShardingDataSource.class));
}
}
...@@ -21,6 +21,7 @@ import com.zhzf.fpj.xcx.demo.mybatis.entity.Order; ...@@ -21,6 +21,7 @@ import com.zhzf.fpj.xcx.demo.mybatis.entity.Order;
import com.zhzf.fpj.xcx.demo.mybatis.entity.OrderItem; import com.zhzf.fpj.xcx.demo.mybatis.entity.OrderItem;
import com.zhzf.fpj.xcx.demo.mybatis.repository.OrderItemRepository; import com.zhzf.fpj.xcx.demo.mybatis.repository.OrderItemRepository;
import com.zhzf.fpj.xcx.demo.mybatis.repository.OrderRepository; import com.zhzf.fpj.xcx.demo.mybatis.repository.OrderRepository;
import com.zhzf.fpj.xcx.utils.DateUtil;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -36,17 +37,18 @@ public class DemoService { ...@@ -36,17 +37,18 @@ public class DemoService {
@Resource @Resource
private OrderItemRepository orderItemRepository; private OrderItemRepository orderItemRepository;
public void demo() { public void demo(String fromapp) {
orderRepository.createIfNotExistsTable(); orderRepository.createIfNotExistsTable();
orderItemRepository.createIfNotExistsTable(); orderItemRepository.createIfNotExistsTable();
orderRepository.truncateTable(); //orderRepository.truncateTable();
orderItemRepository.truncateTable(); //orderItemRepository.truncateTable();
List<Long> orderIds = new ArrayList<Long>(10); List<Long> orderIds = new ArrayList<Long>(10);
System.out.println("1.Insert--------------"); System.out.println("1.Insert--------------");
for (int i = 0; i < 100; i++) { String ds = DateUtil.getCurrentTimestamp();
for (int i = 0; i < 4; i++) {
Order order = new Order(); Order order = new Order();
order.setUserId(i); order.setUserId(i);
order.setStatus("INSERT_TEST"); order.setStatus("INSERT_TEST_"+fromapp+" "+ds);
orderRepository.insert(order); orderRepository.insert(order);
long orderId = order.getOrderId(); long orderId = order.getOrderId();
orderIds.add(orderId); orderIds.add(orderId);
...@@ -54,7 +56,7 @@ public class DemoService { ...@@ -54,7 +56,7 @@ public class DemoService {
OrderItem item = new OrderItem(); OrderItem item = new OrderItem();
item.setOrderId(orderId); item.setOrderId(orderId);
item.setUserId(i); item.setUserId(i);
item.setStatus("INSERT_TEST"); item.setStatus("INSERT_TEST_"+fromapp+" "+ds);
orderItemRepository.insert(item); orderItemRepository.insert(item);
} }
System.out.println(orderItemRepository.selectAll()); System.out.println(orderItemRepository.selectAll());
......
sharding.jdbc.datasource.names=ds_0,ds_1
sharding.jdbc.datasource.ds_0.type=org.apache.commons.dbcp.BasicDataSource
sharding.jdbc.datasource.ds_0.driver-class-name=com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds_0.url=jdbc:mysql://115.28.171.4:3306/demo_ds_0
sharding.jdbc.datasource.ds_0.username=root
sharding.jdbc.datasource.ds_0.password=123456
sharding.jdbc.datasource.ds_1.type=org.apache.commons.dbcp.BasicDataSource
sharding.jdbc.datasource.ds_1.driver-class-name=com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds_1.url=jdbc:mysql://115.28.171.4:3306/demo_ds_1
sharding.jdbc.datasource.ds_1.username=root
sharding.jdbc.datasource.ds_1.password=123456
sharding.jdbc.config.sharding.default-database-strategy.inline.sharding-column=user_id
sharding.jdbc.config.sharding.default-database-strategy.inline.algorithm-expression=ds_${user_id % 2}
sharding.jdbc.config.sharding.tables.t_order.actual-data-nodes=ds_${0..1}.t_order_${0..1}
sharding.jdbc.config.sharding.tables.t_order.table-strategy.inline.sharding-column=order_id
sharding.jdbc.config.sharding.tables.t_order.table-strategy.inline.algorithm-expression=t_order_${order_id % 2}
sharding.jdbc.config.sharding.tables.t_order.key-generator-column-name=order_id
sharding.jdbc.config.sharding.tables.t_order_item.actual-data-nodes=ds_${0..1}.t_order_item_${0..1}
sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.sharding-column=order_id
sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.algorithm-expression=t_order_item_${order_id % 2}
sharding.jdbc.config.sharding.tables.t_order_item.key-generator-column-name=order_item_id
sharding.jdbc.config.sharding.props.sql.show=false
sharding.jdbc.config.orchestration.name=demo_spring_boot_ds_sharding
sharding.jdbc.config.orchestration.type=sharding
sharding.jdbc.config.orchestration.overwrite=false
sharding.jdbc.config.orchestration.zookeeper.namespace=orchestration-spring-boot-demo
sharding.jdbc.config.orchestration.zookeeper.server-lists=localhost:2181
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="log.context.name" value="sharding-jdbc-spring-namespace-jpa-example" />
<property name="log.charset" value="UTF-8" />
<property name="log.pattern" value="[%-5level] %date --%thread-- [%logger] %msg %n" />
<contextName>${log.context.name}</contextName>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder charset="${log.charset}">
<pattern>${log.pattern}</pattern>
</encoder>
</appender>
<logger name="org.springframework" level="WARN" />
<logger name="com.zaxxer.hikari" level="WARN" />
<root>
<level value="DEBUG" />
<appender-ref ref="STDOUT" />
</root>
</configuration>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>core-buiness-demo-sec</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>buiness-service-demo-sec</artifactId>
<name>buiness-service-demo-sec</name>
<description>buiness-service-demo-sec</description>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>buiness-dao-demo-sec</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file \ No newline at end of file
...@@ -12,8 +12,8 @@ public class DemoServiceIn { ...@@ -12,8 +12,8 @@ public class DemoServiceIn {
private DemoService demoService; private DemoService demoService;
public void testExecute(String appfrom){ public void testExecute(String appfrom){
System.out.println("#######testExecute ["+ appfrom+"] #########"); System.out.println("#######demo-sec-testExecute ["+ appfrom+"] #########");
demoService.demo(); demoService.demo(appfrom);
} }
......
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>core-buiness</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>core-buiness-demo-sec</artifactId>
<name>core-buiness-demo-sec</name>
<description>core-buiness-demo-sec 业务代码的输出</description>
<packaging>pom</packaging>
<modules>
<module>buiness-service-demo-sec</module>
<module>buiness-dao-demo-sec</module>
</modules>
<dependencies>
</dependencies>
</project>
\ No newline at end of file \ No newline at end of file
...@@ -6,13 +6,17 @@ ...@@ -6,13 +6,17 @@
<artifactId>core-buiness-demo</artifactId> <artifactId>core-buiness-demo</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
</parent> </parent>
<artifactId>demo-dao</artifactId> <artifactId>buiness-dao-demo</artifactId>
<name>demo-dao</name> <name>buiness-dao-demo</name>
<description>demo-dao</description> <description>buiness-dao-demo</description>
<packaging>jar</packaging> <packaging>jar</packaging>
<dependencies> <dependencies>
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>common-fk-base</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -18,10 +18,16 @@ ...@@ -18,10 +18,16 @@
package com.zhzf.fpj.xcx.demo.mybatis; package com.zhzf.fpj.xcx.demo.mybatis;
import com.zhzf.fpj.xcx.demo.mybatis.service.DemoService; import com.zhzf.fpj.xcx.demo.mybatis.service.DemoService;
import com.zhzf.fpj.xcx.envir.ApplicationEnvironmentPreparedEventListener;
import com.zhzf.fpj.xcx.envir.ApplicationListener2;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource; import org.springframework.context.annotation.PropertySource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
@SpringBootApplication @SpringBootApplication
//@PropertySource(ignoreResourceNotFound=true,value="classpath:application-dao.properties") //@PropertySource(ignoreResourceNotFound=true,value="classpath:application-dao.properties")
...@@ -30,7 +36,24 @@ public class SpringBootDataMybatisMain { ...@@ -30,7 +36,24 @@ public class SpringBootDataMybatisMain {
// CHECKSTYLE:OFF // CHECKSTYLE:OFF
public static void main(final String[] args) { public static void main(final String[] args) {
// CHECKSTYLE:ON // CHECKSTYLE:ON
ApplicationContext applicationContext = SpringApplication.run(SpringBootDataMybatisMain.class, args);
applicationContext.getBean(DemoService.class).demo(); // ApplicationContext applicationContext = SpringApplication.run(SpringBootDataMybatisMain.class, args);
// applicationContext.getBean(DemoService.class).demo();
Object[] starts = new Object[1];
starts[0] = SpringBootDataMybatisMain.class;
SpringApplication app = new SpringApplication(starts);
app.addListeners(new ApplicationEnvironmentPreparedEventListener());
app.addListeners(new ApplicationListener2());
ApplicationContext applicationContext = app.run(args);
//applicationContext.getBean(DemoService.class).demo("local_demo_dao");
} }
} }
/*
* Copyright 1999-2015 dangdang.com.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* </p>
*/
package com.zhzf.fpj.xcx.demo.mybatis.entity;
public final class Order {
private long orderId;
private int userId;
private String status;
public long getOrderId() {
return orderId;
}
public void setOrderId(final long orderId) {
this.orderId = orderId;
}
public int getUserId() {
return userId;
}
public void setUserId(final int userId) {
this.userId = userId;
}
public String getStatus() {
return status;
}
public void setStatus(final String status) {
this.status = status;
}
@Override
public String toString() {
return String.format("order_id: %s, user_id: %s, status: %s", orderId, userId, status);
}
}
/*
* Copyright 1999-2015 dangdang.com.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* </p>
*/
package com.zhzf.fpj.xcx.demo.mybatis.entity;
public final class OrderItem {
private long orderItemId;
private long orderId;
private int userId;
private String status;
public long getOrderItemId() {
return orderItemId;
}
public void setOrderItemId(final long orderItemId) {
this.orderItemId = orderItemId;
}
public long getOrderId() {
return orderId;
}
public void setOrderId(final long orderId) {
this.orderId = orderId;
}
public int getUserId() {
return userId;
}
public void setUserId(final int userId) {
this.userId = userId;
}
public String getStatus() {
return status;
}
public void setStatus(final String status) {
this.status = status;
}
@Override
public String toString() {
return String.format("item_id:%s, order_id: %s, user_id: %s, status: %s", orderItemId, orderId, userId, status);
}
}
/*
* Copyright 1999-2015 dangdang.com.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* </p>
*/
package com.zhzf.fpj.xcx.demo.mybatis.repository;
import com.zhzf.fpj.xcx.demo.mybatis.entity.OrderItem;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface OrderItemRepository {
void createIfNotExistsTable();
void truncateTable();
Long insert(OrderItem model);
void delete(Long orderItemId);
List<OrderItem> selectAll();
void dropTable();
}
/*
* Copyright 1999-2015 dangdang.com.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* </p>
*/
package com.zhzf.fpj.xcx.demo.mybatis.repository;
import com.zhzf.fpj.xcx.demo.mybatis.entity.Order;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface OrderRepository {
void createIfNotExistsTable();
void truncateTable();
Long insert(Order model);
void delete(Long orderId);
void dropTable();
}
/*
* Copyright 1999-2015 dangdang.com.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* </p>
*/
package com.zhzf.fpj.xcx.demo.mybatis.service;
import com.zhzf.fpj.xcx.demo.mybatis.entity.Order;
import com.zhzf.fpj.xcx.demo.mybatis.entity.OrderItem;
import com.zhzf.fpj.xcx.demo.mybatis.repository.OrderItemRepository;
import com.zhzf.fpj.xcx.demo.mybatis.repository.OrderRepository;
import com.zhzf.fpj.xcx.utils.DateUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
public class DemoService {
@Resource
private OrderRepository orderRepository;
@Resource
private OrderItemRepository orderItemRepository;
public void demo(String fromapp) {
orderRepository.createIfNotExistsTable();
orderItemRepository.createIfNotExistsTable();
//orderRepository.truncateTable();
//orderItemRepository.truncateTable();
List<Long> orderIds = new ArrayList<Long>(10);
System.out.println("1.Insert--------------");
String ds = DateUtil.getCurrentTimestamp();
for (int i = 0; i < 4; i++) {
Order order = new Order();
order.setUserId(i);
order.setStatus("INSERT_TEST_"+fromapp+" "+ds);
orderRepository.insert(order);
long orderId = order.getOrderId();
orderIds.add(orderId);
OrderItem item = new OrderItem();
item.setOrderId(orderId);
item.setUserId(i);
item.setStatus("INSERT_TEST_"+fromapp+" "+ds);
orderItemRepository.insert(item);
}
System.out.println(orderItemRepository.selectAll());
System.out.println("2.Delete--------------");
for (Long each : orderIds) {
//orderRepository.delete(each);
//orderItemRepository.delete(each);
}
System.out.println(orderItemRepository.selectAll());
//orderItemRepository.dropTable();
//orderRepository.dropTable();
}
}
<?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="com.zhzf.fpj.xcx.demo.mybatis.repository.OrderItemRepository">
<resultMap id="baseResultMap" type="com.zhzf.fpj.xcx.demo.mybatis.entity.OrderItem">
<result column="order_item_id" property="orderItemId" jdbcType="INTEGER"/>
<result column="order_id" property="orderId" jdbcType="INTEGER"/>
<result column="user_id" property="userId" jdbcType="INTEGER"/>
<result column="status" property="status" jdbcType="VARCHAR"/>
</resultMap>
<update id="createIfNotExistsTable">
CREATE TABLE IF NOT EXISTS t_order_item (order_item_id BIGINT AUTO_INCREMENT, order_id BIGINT, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_item_id));
</update>
<update id="truncateTable">
TRUNCATE TABLE t_order_item;
</update>
<update id="dropTable">
DROP TABLE IF EXISTS t_order_item;
</update>
<insert id="insert" useGeneratedKeys="true" keyProperty="orderItemId">
INSERT INTO t_order_item (
order_id, user_id, status
)
VALUES (
#{orderId,jdbcType=INTEGER},
#{userId,jdbcType=INTEGER},
#{status,jdbcType=VARCHAR}
)
</insert>
<delete id="delete">
DELETE FROM t_order_item WHERE order_id = #{orderId,jdbcType=INTEGER}
</delete>
<select id="selectAll" resultMap="baseResultMap">
SELECT
i.*
FROM
t_order o, t_order_item i
WHERE
o.order_id = i.order_id
</select>
</mapper>
<?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="com.zhzf.fpj.xcx.demo.mybatis.repository.OrderRepository">
<update id="createIfNotExistsTable">
CREATE TABLE IF NOT EXISTS t_order (order_id BIGINT AUTO_INCREMENT, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id));
</update>
<update id="truncateTable">
TRUNCATE TABLE t_order;
</update>
<update id="dropTable">
DROP TABLE IF EXISTS t_order;
</update>
<insert id="insert" useGeneratedKeys="true" keyProperty="orderId">
INSERT INTO t_order (
user_id, status
)
VALUES (
#{userId,jdbcType=INTEGER},
#{status,jdbcType=VARCHAR}
)
</insert>
<delete id="delete">
DELETE FROM t_order WHERE order_id = #{orderId,jdbcType=INTEGER}
</delete>
</mapper>
<?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="logImpl" value="STDOUT_LOGGING" />-->
<!--</settings>-->
<typeAliases>
<package name="com.zhzf.fpj.xcx.demo.mybatis.entity"/>
</typeAliases>
<mappers>
<mapper resource="META-INF/mappers/OrderMapper.xml"/>
<mapper resource="META-INF/mappers/OrderItemMapper.xml"/>
</mappers>
</configuration>
sharding.jdbc.datasource.names=ds_0,ds_1 sharding.jdbc.datasource.names=ds_0,ds_1
sharding.jdbc.datasource.ds_0.type=com.alibaba.druid.pool.DruidDataSource sharding.jdbc.datasource.ds_0.type=com.alibaba.druid.pool.DruidDataSource
sharding.jdbc.datasource.ds_0.driver-class-name=com.mysql.jdbc.Driver sharding.jdbc.datasource.ds_0.driver-class-name=com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds_0.url=jdbc:mysql://115.28.171.4:3306/demo_ds_0 sharding.jdbc.datasource.ds_0.url=jdbc:mysql://115.28.171.4:3306/demo_ds_0
......
spring.jpa.properties.hibernate.hbm2ddl.auto=create
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
#spring.jpa.properties.hibernate.show_sql=true
mybatis.config-location=classpath:META-INF/mybatis-config.xml
spring.profiles.active=sharding
#spring.profiles.active=sharding-db
#spring.profiles.active=sharding-tbl
#spring.profiles.active=masterslave
#spring.profiles.active=sharding-masterslave
...@@ -6,16 +6,16 @@ ...@@ -6,16 +6,16 @@
<artifactId>core-buiness-demo</artifactId> <artifactId>core-buiness-demo</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
</parent> </parent>
<artifactId>demo-service</artifactId> <artifactId>buiness-service-demo</artifactId>
<name>demo-service</name> <name>buiness-service-demo</name>
<description>demo-service</description> <description>buiness-service-demo</description>
<packaging>jar</packaging> <packaging>jar</packaging>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.zhzf.fpj.xcx</groupId> <groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>demo-dao</artifactId> <artifactId>buiness-dao-demo</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
</dependencies> </dependencies>
......
package com.zhzf.fpj.xcx.demo.service;
import com.zhzf.fpj.xcx.demo.mybatis.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class DemoServiceIn {
@Autowired(required = false)
private DemoService demoService;
public void testExecute(String appfrom){
System.out.println("#######demo-testExecute ["+ appfrom+"] #########");
demoService.demo(appfrom);
}
}
package com.zhzf.fpj.xcx.demo.service;
import com.zhzf.fpj.xcx.demo.mybatis.SpringBootDataMybatisMain;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
//@ComponentScan("com.zhzf.fpj.xcx.demo")
public class SpringBootDataServiceMain {
// CHECKSTYLE:OFF
public static void main(final String[] args) {
// CHECKSTYLE:ON
Object[] starts = new Object[2];
starts[0] = SpringBootDataMybatisMain.class;
starts[1] = SpringBootDataServiceMain.class;
ApplicationContext applicationContext = SpringApplication.run(starts, args);
//ApplicationContext applicationContext = SpringApplication.run(com.zhzf.fpj.xcx.demo.service.SpringBootDataServiceMain.class, args);
//applicationContext.getBean(DemoServiceIn.class).testExecute();
}
}
...@@ -12,13 +12,16 @@ ...@@ -12,13 +12,16 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>
<module>demo-service</module> <module>buiness-service-demo</module>
<module>demo-dao</module> <module>buiness-dao-demo</module>
</modules> </modules>
<dependencies> <dependencies>
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>common-fk-base</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file \ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.zhzf.fpj.xcx</groupId> <groupId>com.zhzf.fpj.xcx</groupId>
...@@ -7,11 +8,12 @@ ...@@ -7,11 +8,12 @@
</parent> </parent>
<artifactId>core-buiness</artifactId> <artifactId>core-buiness</artifactId>
<name>core-buiness</name> <name>core-buiness</name>
<description>core-buiness 业务代码的输出 </description> <description>core-buiness 业务代码的输出</description>
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>
<module>core-buiness-demo</module> <module>core-buiness-demo</module>
<module>core-buiness-demo-sec</module>
</modules> </modules>
...@@ -40,6 +42,26 @@ ...@@ -40,6 +42,26 @@
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
</dependency> </dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>common-fk-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>core-common-util</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file \ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>fpj-xcx</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>core-common-beans</artifactId>
<name>core-common-beans</name>
<description>项目的公共的beans</description>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.2</version>
<configuration>
<aggregate>true</aggregate>
<tags>
<tag>
<name>Description</name>
<placement>a</placement>
<head>用途</head>
</tag>
</tags>
<reportOutputDirectory>target/report_output</reportOutputDirectory>
<destDir>target/apidocs</destDir>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file \ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>fpj-xcx</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>core-common-util</artifactId>
<name>core-common-util</name>
<description>项目的公共的util</description>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</dependency>
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>core-common-beans</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.2</version>
<configuration>
<aggregate>true</aggregate>
<tags>
<tag>
<name>Description</name>
<placement>a</placement>
<head>用途</head>
</tag>
</tags>
<reportOutputDirectory>target/report_output</reportOutputDirectory>
<destDir>target/apidocs</destDir>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file \ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>fpj-xcx</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>core-interactive</artifactId>
<name>core-interactive</name>
<description>core-interactive</description>
<dependencies>
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>core-common-util</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.2</version>
<configuration>
<aggregate>true</aggregate>
<tags>
<tag>
<name>Description</name>
<placement>a</placement>
<head>用途</head>
</tag>
</tags>
<reportOutputDirectory>target/report_output</reportOutputDirectory>
<destDir>target/apidocs</destDir>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file \ No newline at end of file
...@@ -22,13 +22,13 @@ ...@@ -22,13 +22,13 @@
<dependency> <dependency>
<groupId>com.zhzf.fpj.xcx</groupId> <groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>demo-service</artifactId> <artifactId>buiness-service-demo-sec</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.zhzf.fpj.xcx</groupId> <groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>demo-dao</artifactId> <artifactId>buiness-dao-demo-sec</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
......
package com.zhzf.fpj.xcx.bootstart;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import java.util.ArrayList;
import java.util.List;
@Configuration
public class ApplicationConfigurer {
static Logger logger = LoggerFactory.getLogger(ApplicationConfigurer.class);
public static final String SPRING_CONFIG_LOCATION = "spring.config.location";
/**
* 自定义配置加载,方法定义为static的,保证优先加载
* @return
*/
@Bean
public static PropertyPlaceholderConfigurer properties() {
final PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
ppc.setIgnoreResourceNotFound(true);
final List<Resource> resourceLst = new ArrayList<Resource>();
logger.info("ApplicationConfigurer.............");
if(System.getProperty(SPRING_CONFIG_LOCATION) != null){
String configFilePath = System.getProperty(SPRING_CONFIG_LOCATION);
String[] configFiles = configFilePath.split(",|;");
FileSystemResource res =null;
for (String configFile : configFiles) {
if (configFile.startsWith("file:")){
resourceLst.add(new FileSystemResource(configFile));
}else {
resourceLst.add( new ClassPathResource(configFile));
}
}
}else {
//resourceLst.add(new ClassPathResource("config/application.properties"));
//resourceLst.add(new ClassPathResource("config/kafka.properties"));
}
ppc.setLocations(resourceLst.toArray(new Resource[]{}));
return ppc;
}
}
\ No newline at end of file \ No newline at end of file
...@@ -2,8 +2,14 @@ package com.zhzf.fpj.xcx.bootstart; ...@@ -2,8 +2,14 @@ package com.zhzf.fpj.xcx.bootstart;
import com.zhzf.fpj.xcx.demo.mybatis.SpringBootDataMybatisMain; import com.zhzf.fpj.xcx.demo.mybatis.SpringBootDataMybatisMain;
import com.zhzf.fpj.xcx.demo.service.SpringBootDataServiceMain; import com.zhzf.fpj.xcx.demo.service.SpringBootDataServiceMain;
import com.zhzf.fpj.xcx.envir.ApplicationEnvironmentPreparedEventListener;
import com.zhzf.fpj.xcx.envir.ApplicationListener2;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
@SpringBootApplication @SpringBootApplication
public class ServiceBootStartApplication { public class ServiceBootStartApplication {
...@@ -14,7 +20,12 @@ public class ServiceBootStartApplication { ...@@ -14,7 +20,12 @@ public class ServiceBootStartApplication {
starts[0] = SpringBootDataMybatisMain.class; starts[0] = SpringBootDataMybatisMain.class;
starts[1] = SpringBootDataServiceMain.class; starts[1] = SpringBootDataServiceMain.class;
starts[2] = ServiceBootStartApplication.class; starts[2] = ServiceBootStartApplication.class;
SpringApplication.run(starts, args);
SpringApplication app = new SpringApplication(starts);
app.addListeners(new ApplicationEnvironmentPreparedEventListener());
app.addListeners(new ApplicationListener2());
app.run(args);
try { try {
System.in.read(); System.in.read();
} catch (Exception e) { } catch (Exception e) {
...@@ -23,4 +34,6 @@ public class ServiceBootStartApplication { ...@@ -23,4 +34,6 @@ public class ServiceBootStartApplication {
} }
} }
package com.zhzf.fpj.xcx.service; package com.zhzf.fpj.xcx.service;
import com.alibaba.dubbo.config.annotation.Service; import com.alibaba.dubbo.config.annotation.Service;
import com.zhzf.fpj.xcx.demo.DemoService; import com.zhzf.fpj.xcx.api.demo.DemoService;
import com.zhzf.fpj.xcx.demo.service.DemoServiceIn; import com.zhzf.fpj.xcx.demo.service.DemoServiceIn;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
......
...@@ -2,11 +2,6 @@ spring: ...@@ -2,11 +2,6 @@ spring:
application: application:
name: dubbo-provider-demo name: dubbo-provider-demo
server:
port: 9090
management:
port: 9091
dubbo: dubbo:
scan: scan:
...@@ -17,7 +12,7 @@ dubbo: ...@@ -17,7 +12,7 @@ dubbo:
protocol: protocol:
id: dubbo id: dubbo
name: dubbo name: dubbo
port: 12345 port: 30001
registry: registry:
id: my-registry id: my-registry
address: N/A address: N/A
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>core-services</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>core-service-notice</artifactId>
<name>core-service-notice</name>
<description>core-service-notice</description>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>core-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>buiness-service-demo</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>buiness-dao-demo</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file \ No newline at end of file
package com.zhzf.fpj.xcx.bootstart;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import java.util.ArrayList;
import java.util.List;
@Configuration
public class ApplicationConfigurer {
static Logger logger = LoggerFactory.getLogger(ApplicationConfigurer.class);
public static final String SPRING_CONFIG_LOCATION = "spring.config.location";
/**
* 自定义配置加载,方法定义为static的,保证优先加载
* @return
*/
@Bean
public static PropertyPlaceholderConfigurer properties() {
final PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
ppc.setIgnoreResourceNotFound(true);
final List<Resource> resourceLst = new ArrayList<Resource>();
logger.info("ApplicationConfigurer.............");
if(System.getProperty(SPRING_CONFIG_LOCATION) != null){
String configFilePath = System.getProperty(SPRING_CONFIG_LOCATION);
String[] configFiles = configFilePath.split(",|;");
FileSystemResource res =null;
for (String configFile : configFiles) {
if (configFile.startsWith("file:")){
resourceLst.add(new FileSystemResource(configFile));
}else {
resourceLst.add( new ClassPathResource(configFile));
}
}
}else {
//resourceLst.add(new ClassPathResource("config/application.properties"));
//resourceLst.add(new ClassPathResource("config/kafka.properties"));
}
ppc.setLocations(resourceLst.toArray(new Resource[]{}));
return ppc;
}
}
\ No newline at end of file \ No newline at end of file
package com.zhzf.fpj.xcx.bootstart;
import com.zhzf.fpj.xcx.demo.mybatis.SpringBootDataMybatisMain;
import com.zhzf.fpj.xcx.demo.service.SpringBootDataServiceMain;
import com.zhzf.fpj.xcx.envir.ApplicationEnvironmentPreparedEventListener;
import com.zhzf.fpj.xcx.envir.ApplicationListener2;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
@SpringBootApplication
public class ServiceBootStartApplication {
public static void main(String[] args) {
Object[] starts = new Object[3];
starts[0] = SpringBootDataMybatisMain.class;
starts[1] = SpringBootDataServiceMain.class;
starts[2] = ServiceBootStartApplication.class;
SpringApplication app = new SpringApplication(starts);
app.addListeners(new ApplicationEnvironmentPreparedEventListener());
app.addListeners(new ApplicationListener2());
app.run(args);
try {
System.in.read();
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.zhzf.fpj.xcx.service;
import com.alibaba.dubbo.config.annotation.Service;
import com.zhzf.fpj.xcx.api.demo.DemoService;
import com.zhzf.fpj.xcx.api.demo.DemoServiceOther;
import com.zhzf.fpj.xcx.demo.service.DemoServiceIn;
import org.springframework.beans.factory.annotation.Autowired;
@Service(
version = "1.0.0",
application = "${dubbo.application.id}",
protocol = "${dubbo.protocol.id}",
registry = "${dubbo.registry.id}"
)
public class TestDemoService implements DemoServiceOther {
@Autowired(required = false)
private DemoServiceIn demoServiceIn;
public String sayHelloOther(String name) {
demoServiceIn.testExecute("notice");
return "Hello, " + name + " (from Spring Boot)";
}
}
\ No newline at end of file \ No newline at end of file
...@@ -4,7 +4,7 @@ server.port = 9090 ...@@ -4,7 +4,7 @@ server.port = 9090
management.port = 9091 management.port = 9091
# Base packages to scan Dubbo Components (e.g., @Service, @Reference) # Base packages to scan Dubbo Components (e.g., @Service, @Reference)
dubbo.scan.basePackages = com.alibaba.boot.dubbo.demo.provider.service dubbo.scan.basePackages = com.zhzf.fpj.xcx.service
# Dubbo Config properties # Dubbo Config properties
## ApplicationConfig Bean ## ApplicationConfig Bean
......
spring:
application:
name: dubbo-provider-notice
dubbo:
scan:
basePackages: com.zhzf.fpj.xcx.service
application:
id: dubbo-provider-notice
name: dubbo-provider-notice
protocol:
id: dubbo
name: dubbo
port: 30002
registry:
id: my-registry
address: N/A
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
<modules> <modules>
<module>core-service-demo</module> <module>core-service-demo</module>
<module>core-service-notice</module>
</modules> </modules>
<dependencies> <dependencies>
...@@ -60,6 +61,27 @@ ...@@ -60,6 +61,27 @@
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
</dependency> </dependency>
<!--业务内部的关键依赖-->
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>common-fk-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>core-common-beans</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>core-common-util</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file \ No newline at end of file
...@@ -58,6 +58,28 @@ ...@@ -58,6 +58,28 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!--业务内部的关键依赖-->
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>core-common-beans</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>core-common-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>core-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file \ No newline at end of file
...@@ -3,7 +3,8 @@ package com.zhzf.fpj.xcx.web.controller; ...@@ -3,7 +3,8 @@ package com.zhzf.fpj.xcx.web.controller;
import com.alibaba.dubbo.config.annotation.Reference; import com.alibaba.dubbo.config.annotation.Reference;
import com.zhzf.fpj.xcx.demo.DemoService; import com.zhzf.fpj.xcx.api.demo.DemoService;
import com.zhzf.fpj.xcx.api.demo.DemoServiceOther;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -14,12 +15,27 @@ public class DemoConsumerController { ...@@ -14,12 +15,27 @@ public class DemoConsumerController {
@Reference(version = "1.0.0", @Reference(version = "1.0.0",
application = "${dubbo.application.id}", application = "${dubbo.application.id}",
url = "dubbo://localhost:12345",check = false,timeout = 60000 ) url = "dubbo://localhost:30001",check = false,timeout = 60000 )
private DemoService demoService; private DemoService demoService;
@Reference(version = "1.0.0",
application = "${dubbo.application.id}",
url = "dubbo://localhost:30002",check = false,timeout = 60000 )
private DemoServiceOther demoServiceOther;
@RequestMapping("/sayHello") @RequestMapping("/sayHello")
public String sayHello(@RequestParam String name) { public String sayHello(@RequestParam String name) {
return demoService.sayHello(name); return demoService.sayHello(name);
} }
@RequestMapping("/sayHello2")
public String sayHello2(@RequestParam String name) {
return demoServiceOther.sayHelloOther(name);
}
} }
...@@ -13,3 +13,4 @@ dubbo.application.name = dubbo-consumer-demo ...@@ -13,3 +13,4 @@ dubbo.application.name = dubbo-consumer-demo
dubbo.protocol.id = dubbo dubbo.protocol.id = dubbo
dubbo.protocol.name = dubbo dubbo.protocol.name = dubbo
dubbo.protocol.port = 12345 dubbo.protocol.port = 12345
...@@ -11,9 +11,11 @@ ...@@ -11,9 +11,11 @@
<modules> <modules>
<module>common-fk-base</module>
<module>core-common-util</module>
<module>core-api</module> <module>core-api</module>
<!--module>core-common</module--> <module>core-interactive</module>
<!--module>core-domains</module--> <module>core-common-beans</module>
<module>core-services</module> <module>core-services</module>
<module>core-webs</module> <module>core-webs</module>
<module>core-business</module> <module>core-business</module>
...@@ -37,6 +39,13 @@ ...@@ -37,6 +39,13 @@
<mybatis-spring.version>1.3.0</mybatis-spring.version> <mybatis-spring.version>1.3.0</mybatis-spring.version>
<druid_version>1.0.12</druid_version> <druid_version>1.0.12</druid_version>
<!--LOG-->
<slf4j_version>1.7.22</slf4j_version>
<jcl_version>1.1</jcl_version>
<log4j_version>1.2.17</log4j_version>
<logback_version>1.2.0</logback_version>
<logstash_logback_encoder_version>4.8</logstash_logback_encoder_version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
...@@ -91,6 +100,12 @@ ...@@ -91,6 +100,12 @@
<version>${sharding-jdbc.version}</version> <version>${sharding-jdbc.version}</version>
</dependency> </dependency>
<dependency>
<groupId>io.shardingjdbc</groupId>
<artifactId>sharding-jdbc-orchestration-spring-boot-starter</artifactId>
<version>${sharding-jdbc.version}</version>
</dependency>
<dependency> <dependency>
<groupId>com.zaxxer</groupId> <groupId>com.zaxxer</groupId>
...@@ -111,6 +126,52 @@ ...@@ -111,6 +126,52 @@
<version>${druid_version}</version> <version>${druid_version}</version>
</dependency> </dependency>
<!-- Log libs -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j_version}</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging-api</artifactId>
<version>${jcl_version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j_version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback_version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
<version>${logback_version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback_version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${slf4j_version}</version>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>${logstash_logback_encoder_version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!