Commit 6824bdd8 by ethanlamzs

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

2、同时配置启用两个事例提供者服务 与 一个消费者对应
1 parent 8ccacceb
Showing 63 changed files with 2261 additions and 163 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
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
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
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 @@
<name>core-api</name>
<description>core-api</description>
<dependencies>
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>core-common-beans</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
......
package com.zhzf.fpj.xcx.demo;
package com.zhzf.fpj.xcx.api.demo;
public interface DemoService {
......
package com.zhzf.fpj.xcx.api.demo;
public interface DemoServiceOther {
String sayHelloOther(String name);
}
\ 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
/*
* 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;
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;
......@@ -36,17 +37,18 @@ public class DemoService {
@Resource
private OrderItemRepository orderItemRepository;
public void demo() {
public void demo(String fromapp) {
orderRepository.createIfNotExistsTable();
orderItemRepository.createIfNotExistsTable();
orderRepository.truncateTable();
orderItemRepository.truncateTable();
//orderRepository.truncateTable();
//orderItemRepository.truncateTable();
List<Long> orderIds = new ArrayList<Long>(10);
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.setUserId(i);
order.setStatus("INSERT_TEST");
order.setStatus("INSERT_TEST_"+fromapp+" "+ds);
orderRepository.insert(order);
long orderId = order.getOrderId();
orderIds.add(orderId);
......@@ -54,7 +56,7 @@ public class DemoService {
OrderItem item = new OrderItem();
item.setOrderId(orderId);
item.setUserId(i);
item.setStatus("INSERT_TEST");
item.setStatus("INSERT_TEST_"+fromapp+" "+ds);
orderItemRepository.insert(item);
}
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
......@@ -12,8 +12,8 @@ public class DemoServiceIn {
private DemoService demoService;
public void testExecute(String appfrom){
System.out.println("#######testExecute ["+ appfrom+"] #########");
demoService.demo();
System.out.println("#######demo-sec-testExecute ["+ appfrom+"] #########");
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
......@@ -6,13 +6,17 @@
<artifactId>core-buiness-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>demo-dao</artifactId>
<name>demo-dao</name>
<description>demo-dao</description>
<artifactId>buiness-dao-demo</artifactId>
<name>buiness-dao-demo</name>
<description>buiness-dao-demo</description>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>common-fk-base</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
......
......@@ -18,10 +18,16 @@
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 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
//@PropertySource(ignoreResourceNotFound=true,value="classpath:application-dao.properties")
......@@ -30,7 +36,24 @@ 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();
// 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.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.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 @@
<artifactId>core-buiness-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>demo-service</artifactId>
<name>demo-service</name>
<description>demo-service</description>
<artifactId>buiness-service-demo</artifactId>
<name>buiness-service-demo</name>
<description>buiness-service-demo</description>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>demo-dao</artifactId>
<artifactId>buiness-dao-demo</artifactId>
<version>${project.version}</version>
</dependency>
</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 @@
<packaging>pom</packaging>
<modules>
<module>demo-service</module>
<module>demo-dao</module>
<module>buiness-service-demo</module>
<module>buiness-dao-demo</module>
</modules>
<dependencies>
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>common-fk-base</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
\ 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-buiness</artifactId>
<name>core-buiness</name>
<description>core-buiness 业务代码的输出 </description>
<packaging>pom</packaging>
<modules>
<module>core-buiness-demo</module>
</modules>
<dependencies>
<dependency>
<groupId>io.shardingjdbc</groupId>
<artifactId>sharding-jdbc-core-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP-java7</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
<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-buiness</artifactId>
<name>core-buiness</name>
<description>core-buiness 业务代码的输出</description>
<packaging>pom</packaging>
<modules>
<module>core-buiness-demo</module>
<module>core-buiness-demo-sec</module>
</modules>
<dependencies>
<dependency>
<groupId>io.shardingjdbc</groupId>
<artifactId>sharding-jdbc-core-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP-java7</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</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>
</project>
\ 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
<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
package com.zhzf.fpj.xcx.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
/**
*
* 日期转换函数
*
* @author Ethan.Lam 2011-7-24
*
*/
public class DateUtil {
public static final String Formater_yyyy_MM_dd = "yyyy-MM-dd";
public static final String Formater_yyyy_MM_dd_HH_mm_ss = "yyyy-MM-dd HH:mm:ss";
public static final String Formater_yyyyMMddHHmmss = "yyyyMMddHHmmss";
/**
* 判断字符串是否为空
*
* @param str
* @return
*/
public static boolean isNull(String str) {
str = str != null ? str.trim() : str;
return str == null || "".equals(str) ? true : false;
}
/**
*
* 获取当前的时间戳
*
* @return
*/
public static String getCurrentTimestamp() {
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date today = new Date();
return formater.format(today);
}
/**
*
* 获取当前的日期戳
*
* @return
*/
public static String getCurrentDatetamp() {
SimpleDateFormat formater = new SimpleDateFormat(Formater_yyyy_MM_dd);
Date today = new Date();
return formater.format(today);
}
/**
*
* Date 对象转换成对应格式的 字符串
*
* @param date
* @param format
* 如:"yyyy-MM-dd HH:mm:ss",默认:"yyyy-MM-dd HH:mm:ss"
* @return
*
*/
public static String dateToString(Date date, String format) {
if (date == null)
return "";
SimpleDateFormat formater = new SimpleDateFormat(isNull(format) ? "yyyy-MM-dd HH:mm:ss" : format.trim());
return formater.format(date);
}
/**
* 时间友好输出,输出格式 xx月xx日 星期x
* @param date
* @return
*/
public static String frindlyOutPutTime(Date date){
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
String month = calendar.get(Calendar.MONTH) + 1 + "";
String day = calendar.get(Calendar.DAY_OF_MONTH) + "";
String week = DateUtil.getWeek(date).replace("星期","周");
if(month.length()==1){
month="0"+month;
}
if(day.length()==1){
day = "0"+day;
}
return month+"月"+day+"日 "+week;
}
/**
*
* Date 对象转换成对应格式的 字符串
*
* @param date
* 默认:"yyyy-MM-dd HH:mm:ss"
* @return
*
*/
public static String dateToString(Date date) {
if (date == null)
return "";
return dateToString(date, null);
}
/**
*
* Date 对象转换成对应格式的 字符串
*
* @param dateSource
* @param format
* 如:"yyyy-MM-dd HH:mm:ss",默认:"yyyy-MM-dd HH:mm:ss"
* @return
*
*/
public static Date timeStrToDate(String dateSource, String format) {
if (isNull(dateSource))
return null;
SimpleDateFormat formater = new SimpleDateFormat(isNull(format) ? "yyyy-MM-dd HH:mm:ss" : format.trim().replace(".", "-")
.replace("/", "-"));
try {
return formater.parse(dateSource);
} catch (ParseException e) {
e.printStackTrace();
return null;
}
}
/**
*
* Date 对象转换成对应格式的 字符串
*
* @param dateSource
* 默认:"yyyy-MM-dd HH:mm:ss"
* @return
*
*/
public static Date timeStrToDate(String dateSource) {
if (isNull(dateSource))
return null;
return timeStrToDate(dateSource, null);
}
/**
* 得到系统日期
*
* @return
*/
public static String getDate() {
Calendar calendar = Calendar.getInstance();
String year = calendar.get(Calendar.YEAR) + "";
String month = calendar.get(Calendar.MONTH) + 1 + "";
String day = calendar.get(Calendar.DAY_OF_MONTH) + "";
if (month.length() == 1)
month = "0" + month;
if (day.length() == 1)
day = "0" + day;
return year + "-" + month + "-" + day;
}
/**
* 得到当前年份
* @return
*/
public static String getYear(){
Calendar calendar = Calendar.getInstance();
String year = calendar.get(Calendar.YEAR) + "";
return year;
}
/**
* 得到当前月份
* @return
*/
public static String getMonth(){
Calendar calendar = Calendar.getInstance();
String month = calendar.get(Calendar.MONTH) + 1 + "";
return month;
}
/**
* 得到当前日
* @return
*/
public static String getDay(){
Calendar calendar = Calendar.getInstance();
String day = calendar.get(Calendar.DAY_OF_MONTH) + "";
return day;
}
/**
* 得到当前月日
* @return
*/
public static String getMonthDay(){
Calendar calendar = Calendar.getInstance();
String month = calendar.get(Calendar.MONTH) + 1 + "";
String day = calendar.get(Calendar.DAY_OF_MONTH) + "";
return month+day;
}
/**
* 得到系统日期,xx月xx日 xx xx:xx
*
* @return
*/
public static String getWapDate() {
Calendar calendar = Calendar.getInstance();
String month = calendar.get(Calendar.MONTH) + 1 + "";
String day = calendar.get(Calendar.DAY_OF_MONTH) + "";
String hour = calendar.get(Calendar.HOUR_OF_DAY) + "";
String minute = calendar.get(Calendar.MINUTE) + "";
if (month.length() == 1)
month = "0" + month;
return month + "月" + day + "日 " + hour + ":" + minute;
}
/**
* 得到一个时间延后或前移几天的时间,nowdate为时间,delay为前移或后延的天数
*
* @param nowdate
* @param delay
* @return
*/
public static String getNextDay(String nowdate, int delay) {
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String mdate = "";
Date d = timeStrToDate(nowdate);
long myTime = (d.getTime() / 1000) + delay * 24 * 60 * 60;
d.setTime(myTime * 1000);
mdate = format.format(d);
return mdate;
} catch (Exception e) {
return "";
}
}
/**
* 得到一个时间延后或前移几天的时间,nowdate为时间,delay为前移或后延的天数
*
* @param nowdate
* @param delay
* @return
*/
public static String getNextTime(String nowdate, double delay) {
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String mdate = "";
Date d = timeStrToDate(nowdate);
long myTime = (long) ((d.getTime() / 1000) + (delay * 24 * 60 * 60));
d.setTime(myTime * 1000);
mdate = format.format(d);
return mdate;
} catch (Exception e) {
return "";
}
}
/**
* 得到一个时间延后或前移几天的时间,nowdate为时间,delay为前移或后延的天数
*
* @param nowdate
* @param delay
* @return
*/
public static Date getNextDayForDate(Date nowdate, double delay) {
try{
long myTime = (long) ((nowdate.getTime() / 1000) + (delay * 24 * 60 * 60));
nowdate.setTime(myTime * 1000);
return nowdate;
}catch(Exception e){
return null;
}
}
/**
*
* 得到一个时间延后或前移几天的时间,nowdate为时间,delay为前移或后延的天数
*
* @param nowdate
* @param delay
* 小于 0,过去多小天,大于0 未来多小天
* @param dateFormat
* @return
*/
public static String getNextDay(String nowdate, int delay, String dateFormat) {
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String mdate = "";
Date d = timeStrToDate(nowdate, dateFormat);
long myTime = (d.getTime() / 1000) + delay * 24 * 60 * 60;
d.setTime(myTime * 1000);
mdate = format.format(d);
return mdate;
} catch (Exception e) {
return "";
}
}
/**
* 返回今天的时间段
*
* @return yyyy-MM-dd HH:mm:ss
*/
public static String[] getTodayPeriods() {
String today = dateToString(new Date(), Formater_yyyy_MM_dd);
return new String[] { today + " 00:00:00", today + " 23:59:59" };
}
/**
* 返回昨天的时间段
*
* @return yyyy-MM-dd HH:mm:ss
*/
public static String[] getYesterdayPeriods() {
String today = dateToString(new Date(), Formater_yyyy_MM_dd);
String beforeDay = getNextDay(today, -1, Formater_yyyy_MM_dd);
return new String[] { beforeDay + " 00:00:00", beforeDay + " 23:59:59" };
}
/**
* 返回一个星期(7天前)的时间段(含今天)
*
* @return yyyy-MM-dd HH:mm:ss
*/
public static String[] getWeekPeriods() {
String today = dateToString(new Date(), Formater_yyyy_MM_dd);
String beforeDay = getNextDay(today, -6, Formater_yyyy_MM_dd);
return new String[] { beforeDay + " 00:00:00", today + " 23:59:59" };
}
/**
* 返回的一个月时间段(含今天)
*
* @return yyyy-MM-dd HH:mm:ss
*/
public static String[] getMonthDayPeriods(int difMonths) {
difMonths = difMonths == 0 ? 1 : difMonths;
String today = dateToString(new Date(), Formater_yyyy_MM_dd);
String beforeDay = getNextDay(today, -7 * 4 * difMonths - 1, Formater_yyyy_MM_dd);
return new String[] { beforeDay + " 00:00:00", today + " 23:59:59" };
}
/**
* 得到系统当前的时间
*
* @return
*/
public static String getSysDateTime() {
return dateToString(new Date(), DateUtil.Formater_yyyy_MM_dd_HH_mm_ss);
}
/**
* 将calendar的星期几转化为我们习惯的(1-星期一,7-星期日)
*
* @param dayOfWeek
* @return
*/
public static long toChineseWeek(long dayOfWeek) {
return dayOfWeek - 1 == 0 ? 7 : dayOfWeek - 1;
}
/**
* 验证字符串是否是合法的日期
*
* @param dateStr
* @param format
* @return
*/
public static boolean isValidDate(String dateStr, String format) {
try {
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
dateFormat.setLenient(false);
dateFormat.parse(dateStr);
return true;
} catch (Exception e) {
return false;
}
}
/**
* 返回当月的起始 日期 2011-01-01 : 2011-01-31
*
* @return
*/
public static String[] getMonthPeriods(int difMonth) {
Date today = new Date();
int year = today.getYear() + 1900;
int month = today.getMonth() + difMonth + 1;
Calendar c = new GregorianCalendar(today.getYear(), today.getMonth() + difMonth, today.getDate());
// System.out.println(year+" "+month+" "+c.getActualMaximum(Calendar.DATE));
return new String[] { year + "-" + month + "-01", year + "-" + month + "-" + c.getActualMaximum(Calendar.DATE) };
}
/**
* @author linjinyu
* @param time
* @return
*/
public static String getTimeAgoInWords(String time) {
Date date = timeStrToDate(time);
String shortstring = null;
shortstring = getTimeAgoInWords(date);
return shortstring;
}
public static String getTimeAgoInWords(Date date) {
String shortstring = null;
long now = Calendar.getInstance().getTimeInMillis();
if (date == null)
return shortstring;
long deltime = (now - date.getTime()) / 1000;
if (deltime > 365 * 24 * 60 * 60) {
// shortstring = (int)(deltime/(365*24*60*60)) + "年前";
shortstring = DateUtil.dateToString(date, Formater_yyyy_MM_dd);
} else if (deltime > 24 * 60 * 60) {
// shortstring = (int)(deltime/(24*60*60)) + "天前";
shortstring = DateUtil.dateToString(date, "MM-dd HH:mm");
} else if (deltime > 60 * 60) {
shortstring = (int) (deltime / (60 * 60)) + "小时前";
} else if (deltime > 60) {
shortstring = (int) (deltime / (60)) + "分前";
} else if (deltime > 1) {
shortstring = deltime + "秒前";
} else {
shortstring = "1秒前";
}
return shortstring;
}
/**
* @return 时间友好输出 判断 当前时间 与 要比对的时间 ,相差 1 天内返回 今天 ,相差2 天 返回 昨天 或是 2011-03-05
* 这种类型
* @param args
* @author lichengrong
*/
@SuppressWarnings("deprecation")
public static String getDateAgo(Date date, String format) {
String shortstring = null;
Date nowDate = new Date();
if (date == null)
return shortstring;
if (nowDate.getYear() == date.getYear() && nowDate.getMonth() == date.getMonth()) {
// 相同月份
if (nowDate.getDate() == date.getDate()) {
return shortstring = "今天" + DateUtil.dateToString(date, "HH:mm");
} else if (nowDate.getDate() - date.getDate() == 1) {
return shortstring = "昨天" + DateUtil.dateToString(date, "HH:mm");
} else if (nowDate.getDate() - date.getDate() == 2) {
return shortstring = "前天" + DateUtil.dateToString(date, "HH:mm");
} else {
// 直接输出 2011-03-05 这种类型
if (format != null) {
shortstring = DateUtil.dateToString(date, format);
} else {
shortstring = DateUtil.dateToString(date, "MM-dd HH:mm");
}
return shortstring;
}
} else if (nowDate.getYear() == date.getYear() && nowDate.getMonth() != date.getMonth()) {
// 同年不同月
if (format != null) {
shortstring = DateUtil.dateToString(date, format);
} else {
shortstring = DateUtil.dateToString(date, "MM-dd HH:mm");
}
return shortstring;
} else {
// 不同年
shortstring = DateUtil.dateToString(date, Formater_yyyy_MM_dd);
return shortstring;
}
}
public static String getDateAgo(Date date) {
String shortstring = null;
Date nowDate = new Date();
if (date == null)
return shortstring;
if (nowDate.getYear() == date.getYear() && nowDate.getMonth() == date.getMonth()) {
// 相同月份
if (nowDate.getDate() == date.getDate()) {
return shortstring = "今天";
} else if (nowDate.getDate() - date.getDate() == 1) {
return shortstring = "昨天";
} else if (nowDate.getDate() - date.getDate() == 2) {
return shortstring = "前天";
} else {
// 直接输出 2011-03-05 这种类型
shortstring = DateUtil.dateToString(date, Formater_yyyy_MM_dd);
return shortstring;
}
} else if (nowDate.getYear() == date.getYear() && nowDate.getMonth() != date.getMonth()) {
shortstring = DateUtil.dateToString(date, Formater_yyyy_MM_dd);
return shortstring;
} else {
// 不同年
shortstring = DateUtil.dateToString(date, Formater_yyyy_MM_dd);
return shortstring;
}
}
/**
* 传入毫秒数,转换为时间字符串
* @param millis
* @return
*/
public static String millisToDateStr(long millis){
if(millis>0){
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(millis);
return dateToString(calendar.getTime());
}else{
return "";
}
}
/**
*
* 计算体验期的方法(返回截至的日期字符串)
* 计算方法为:
* 体验期:按用户开始体验时间为准,可享受“3(monthsDif)个月+X天” 体验期;(订购当月剩余天数可体验,外加3个月体验时间)
* @param startDayStr “yyyy-MM-dd”
* @param monthsDif
* @return 截至日期的字符串 “yyyy-MM-dd”
*
*/
public static String createExpiredDay(String startDayStr,int monthsDif){
Calendar a = Calendar.getInstance();
int cm = Integer.parseInt(startDayStr.substring(5,7));
int month = (cm + monthsDif>12)?(cm + monthsDif-12)-1:cm + monthsDif-1;
int year = Integer.parseInt(startDayStr.substring(0,4));
a.set(Calendar.YEAR,(cm + monthsDif>12)?year+1:year);
a.set(Calendar.MONTH,month);
a.set(Calendar.DATE, 1);//把日期设置为当月第一天
a.roll(Calendar.DATE, -1);//日期回滚一天,也就是最后一天
return DateUtil.dateToString(a.getTime(),DateUtil.Formater_yyyy_MM_dd);
}
/**
* 计算两个时间之间相差的天数
* @param date1 Start
* @param date2 end
* @return
*/
public static String daysBetween(Date date1,Date date2) {
Calendar cal = Calendar.getInstance();
cal.setTime(date1);
long time1 = cal.getTimeInMillis();
cal.setTime(date2);
long time2 = cal.getTimeInMillis();
long between_days=(time2-time1)/(1000*3600*24);
long left_millis = (time2-time1-(1000*3600*24)*between_days);
long left_hours=left_millis/(1000*3600);
if(left_hours>0){
if(between_days>0)
return String.valueOf(between_days) + "天" + left_hours + "小时";
else
return left_hours + "小时";
}
return String.valueOf(between_days) + "天";
}
/**
* 计算两个时间之间相差的天数
* @param date1 Start
* @param date2 end
* @return
*/
public static String getDaysGap(Date date1,Date date2) {
Calendar cal = Calendar.getInstance();
cal.setTime(date1);
long time1 = cal.getTimeInMillis();
cal.setTime(date2);
long time2 = cal.getTimeInMillis();
long between_days=(time2-time1)/(24*60*60*1000);
long left_millis = (time2-time1-(1000*3600*24)*between_days);
double left_hours=left_millis/(1000*3600);
if(left_hours>0&&left_hours!=12) {
left_hours = 12;
}
if(left_hours>0){
if(between_days>0)
return String.valueOf(between_days+left_hours/24);
else
return left_hours/24+"";
}
return String.valueOf(between_days);
}
/**
* 根据日期取得星期几
* @param date
* @return
*/
public static String getWeek(Date date){
// SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
// String week = sdf.format(date);
// return week;
String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w < 0)
w = 0;
return weekDays[w];
}
public static int getWeekInt(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w < 0)
w = 0;
return w;
}
/**
* 计算离下一个时间点还有多少毫秒
* @param hourPoint 时间点(小时)
* @return
*/
public static long calculatePeriod(int hourPoint){
if(hourPoint<0 || hourPoint>23){
return -1;
}
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
int nowHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
String month = Calendar.getInstance().get(Calendar.MONTH)>10?String.valueOf(Calendar.getInstance().get(Calendar.MONTH)+1):("0"+(Calendar.getInstance().get(Calendar.MONTH)+1));
StringBuilder sb = new StringBuilder();
try {
if(nowHour>=hourPoint){
String day = Calendar.getInstance().get(Calendar.DATE)>=9?String.valueOf(Calendar.getInstance().get(Calendar.DATE)+1):("0"+(Calendar.getInstance().get(Calendar.DATE)+1));
sb.append(year).append(month).append(day).append(hourPoint>9?(hourPoint+""):("0"+hourPoint)).append("0000");
Date executeDate = format.parse(sb.toString());
return executeDate.getTime()-Calendar.getInstance().getTimeInMillis();
}else{
String day = Calendar.getInstance().get(Calendar.DATE)>=10?String.valueOf(Calendar.getInstance().get(Calendar.DATE)):("0"+Calendar.getInstance().get(Calendar.DATE));
sb.append(year).append(month).append(day).append(hourPoint>9?(hourPoint+""):("0"+hourPoint)).append("0000");
Date executeDate = format.parse(sb.toString());
return executeDate.getTime()-Calendar.getInstance().getTimeInMillis();
}
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
/**
* 获取指定的下一个时间点的时间
* @param hour 时间点,小时
* @return
*/
public static Date getNextTimePoint(int hour){
if(hour<0 || hour>23){
return null;
}else{
try {
int nowHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
Calendar cal = Calendar.getInstance();
cal.setTime(format.parse(format.format(new Date())));
if(nowHour<hour){
cal.add(Calendar.HOUR_OF_DAY, hour);
return new Date(cal.getTime().getTime());
}else{
cal.add(Calendar.DAY_OF_YEAR, 1);
return new Date(cal.getTime().getTime()+hour*60*60*1000);
}
} catch (Exception e) {
return null;
}
}
}
/**
* 获取时间当天的起始时间
* @param date
* @return
*/
public static Date getBeginDate(Date date){
Calendar c = Calendar.getInstance();
c.setTime(date);
//设置当前时刻的时钟为0
c.set(Calendar.HOUR_OF_DAY, 0);
//设置当前时刻的分钟为0
c.set(Calendar.MINUTE, 0);
//设置当前时刻的秒钟为0
c.set(Calendar.SECOND, 0);
//设置当前的毫秒钟为0
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
}
/**
* 获取时间当天的结尾时间
* @param date
* @return
*/
public static Date getEndDate(Date date){
Calendar c = Calendar.getInstance();
c.setTime(date);
//设置当前时刻的时钟为23
c.set(Calendar.HOUR_OF_DAY, 23);
//设置当前时刻的分钟为59
c.set(Calendar.MINUTE, 59);
//设置当前时刻的秒钟为59
c.set(Calendar.SECOND, 59);
//设置当前的毫秒钟为999
c.set(Calendar.MILLISECOND, 999);
return c.getTime();
}
public static String getHourAndMinute(String timeStr){
Date time = DateUtil.timeStrToDate(timeStr, "yyyy-MM-dd HH:mm:ss");
Calendar calendar = Calendar.getInstance();
calendar.setTime(time);
String hour = calendar.get(Calendar.HOUR_OF_DAY) + "";
String minute = calendar.get(Calendar.MINUTE) + "";
String second = calendar.get(Calendar.SECOND) + "";
return hour+":"+minute+":"+second;
}
public static void main(String[] args) {
// System.out.println(millisToDateStr(1375312400000L));
// System.out.print(DateUtil.dateToString(new Date(), "yyyyMMdd_HHmmss"));
// Date date = new Date();
// System.out.print(DateUtil.frindlyOutPutTime(date));
System.out.print(DateUtil.getHourAndMinute("2016-03-29 14:37:55"));
}
}
<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
......@@ -22,13 +22,13 @@
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>demo-service</artifactId>
<artifactId>buiness-service-demo-sec</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.zhzf.fpj.xcx</groupId>
<artifactId>demo-dao</artifactId>
<artifactId>buiness-dao-demo-sec</artifactId>
<version>${project.version}</version>
</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
......@@ -2,25 +2,38 @@ 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.run(starts, args);
try {
System.in.read();
} catch (Exception e) {
e.printStackTrace();
}
}
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.demo.DemoService;
import com.zhzf.fpj.xcx.api.demo.DemoService;
import com.zhzf.fpj.xcx.demo.service.DemoServiceIn;
import org.springframework.beans.factory.annotation.Autowired;
......
......@@ -2,11 +2,6 @@ spring:
application:
name: dubbo-provider-demo
server:
port: 9090
management:
port: 9091
dubbo:
scan:
......@@ -17,7 +12,7 @@ dubbo:
protocol:
id: dubbo
name: dubbo
port: 12345
port: 30001
registry:
id: my-registry
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
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
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
......@@ -4,7 +4,7 @@ server.port = 9090
management.port = 9091
# 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
## 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 @@
<modules>
<module>core-service-demo</module>
<module>core-service-notice</module>
</modules>
<dependencies>
......@@ -60,6 +61,27 @@
<artifactId>mysql-connector-java</artifactId>
</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>
</project>
\ No newline at end of file
......@@ -58,6 +58,28 @@
<scope>provided</scope>
</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>
</project>
\ No newline at end of file
......@@ -3,7 +3,8 @@ package com.zhzf.fpj.xcx.web.controller;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
......@@ -14,12 +15,27 @@ public class DemoConsumerController {
@Reference(version = "1.0.0",
application = "${dubbo.application.id}",
url = "dubbo://localhost:12345",check = false,timeout = 60000 )
url = "dubbo://localhost:30001",check = false,timeout = 60000 )
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")
public String sayHello(@RequestParam String 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
dubbo.protocol.id = dubbo
dubbo.protocol.name = dubbo
dubbo.protocol.port = 12345
......@@ -11,9 +11,11 @@
<modules>
<module>common-fk-base</module>
<module>core-common-util</module>
<module>core-api</module>
<!--module>core-common</module-->
<!--module>core-domains</module-->
<module>core-interactive</module>
<module>core-common-beans</module>
<module>core-services</module>
<module>core-webs</module>
<module>core-business</module>
......@@ -37,6 +39,13 @@
<mybatis-spring.version>1.3.0</mybatis-spring.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>
<dependencyManagement>
......@@ -91,6 +100,12 @@
<version>${sharding-jdbc.version}</version>
</dependency>
<dependency>
<groupId>io.shardingjdbc</groupId>
<artifactId>sharding-jdbc-orchestration-spring-boot-starter</artifactId>
<version>${sharding-jdbc.version}</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
......@@ -111,6 +126,52 @@
<version>${druid_version}</version>
</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>
</dependencyManagement>
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!