Commit 8ceb3696 by 共享中心代码生成

Merge branch 'new-strut' into 'master'

New strut

See merge request !2
parents 1eda9fa8 82a6d39e
package com.secoo.mall.dubbo.bean;
package com.secoo.mall.dubbo.dto;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
public class User implements Serializable {
public class UserDto implements Serializable {
@ApiModelProperty(value = "用户姓名")
private String name;
......
package com.secoo.mall.dubbo.service;
import com.secoo.mall.common.core.bean.BizResponse;
import com.secoo.mall.dubbo.bean.User;
import com.secoo.mall.dubbo.dto.UserDto;
public interface UserDService {
BizResponse<String> sayHello(String name);
User getByid(Long id);
UserDto getByid(Long id);
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>matrix-sample-dubbo</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-dubbo-biz</artifactId>
<dependencies>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-dubbo-starter</artifactId>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-sample-dubbo-api</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.secoo.mall.dubbo.filter;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
/**
* 统一拦截异常。
* 不向消费端抛出异常,而是形成response结构.
* 启用自动激活
*/
@Activate(
group = {CommonConstants.PROVIDER}
)
public class DemoResponseExceptionFilter extends MatrixResponseExceptionFilter{
}
package com.secoo.mall.dubbo.filter;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
/**
* 将业务抛出的runtimeException由warn进行输出。
* 如果使用需要激活@Activate
*/
/*@Activate(
group = {CommonConstants.PROVIDER}
)*/
public class DemoWarnExceptionFilter extends MatrixExceptionFilter {
}
package com.secoo.mall.dubbo.service;
import com.secoo.mall.common.core.errorcode.ErrorCode;
import com.secoo.mall.common.core.exception.BusinessException;
import com.secoo.mall.dubbo.dto.UserDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.stereotype.Service;
//import com.secoo.mall.common.util.web.WebUtil;
@Service
@Slf4j
public class UserService {
public String sayHello(String name) {
//模拟抛出异常
if (true) {
ErrorCode errorCode = new ErrorCode(1, "project_not_exist");
throw new BusinessException(errorCode);
}
log.info("Hello {}, request from consumer: {}", name, RpcContext.getContext().getRemoteAddress());
return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress();
}
public UserDto getById(Long id) {
//正常情况下需要做bean到DTO的BeanCopy
UserDto u = new UserDto();
u.setName("liqiuweitest");
return u;
}
}
warnException=com.secoo.mall.dubbo.filter.DemoWarnExceptionFilter
responseException=com.secoo.mall.dubbo.filter.DemoResponseExceptionFilter
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>matrix-sample-dubbo-springboot</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-dubbo-springboot-c</artifactId>
<dependencies>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-dubbo-starter</artifactId>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-sample-dubbo-api</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.secoo.mall.dubbo;
import com.secoo.mall.dubbo.client.UserServiceClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import javax.annotation.Resource;
@SpringBootApplication
@Slf4j
public class DubboConsumerBootstrap implements ApplicationRunner {
public static void main(String[] args) {
SpringApplication.run(DubboConsumerBootstrap.class).close();
}
@Resource
private UserServiceClient userServiceClient;
@Override
public void run(ApplicationArguments args) throws Exception {
log.info("ret:{}", userServiceClient.sayHello("hello"));
}
}
package com.secoo.mall.dubbo.client;
import com.secoo.mall.common.core.bean.BizResponse;
import com.secoo.mall.dubbo.service.UserDService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class UserServiceClient {
@Reference(version = "1.0.0", check = false)
private UserDService userDService;
public String sayHello(String param) {
BizResponse<String> response = userDService.sayHello("hello");
if (response.isSuccess()) {
return response.getData();
}
log.error("code:{},msg:{}",response.getCode(),response.getMsg());
return null;
}
}
server.port=8081
spring.application.name=dubbo-auto-configure-consumer-sample
dubbo.registry.address=zookeeper://127.0.0.1:2181
#dubbo.registry.address=nacos://127.0.0.1:8848
#dubbo.registry.address=zookeeper://dev01-zk-mall1.secoolocal.com:2181?backup=dev01-zk-mall2.secoolocal.com:2181,dev01-zk-mall3.secoolocal.com:2181
\ No newline at end of file
###set log levels###
log4j.rootLogger=info, stdout
###output to the console###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy HH:mm:ss:SSS z}] %t %5p %c{2}: %m%n
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>matrix-sample-dubbo-springboot</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-dubbo-springboot-p</artifactId>
<dependencies>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-sample-dubbo-biz</artifactId>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-dubbo-starter</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.secoo.mall.dubbo;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
@SpringBootApplication
public class DubboProviderBootstrap {
public static void main(String[] args) {
new SpringApplicationBuilder(DubboProviderBootstrap.class)
.run(args);
}
}
\ No newline at end of file
package com.secoo.mall.dubbo.provider;
import com.secoo.mall.common.core.bean.BizResponse;
import com.secoo.mall.common.util.response.ResponseUtil;
import com.secoo.mall.dubbo.dto.UserDto;
import com.secoo.mall.dubbo.service.UserDService;
import com.secoo.mall.dubbo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Service;
import javax.annotation.Resource;
/**
* dubbo-协议使用示例
*/
@Api(value = "用户管理", tags = "用户管理")
@Service(version = "1.0.0")
public class UserProvider implements UserDService {
@Resource
private UserService service;
/**
* 示例:
* 1.异常增强
* 2.swagger导出
*
* @param name
* @return
*/
@Override
@ApiOperation(value = "根据用户名称查询", notes = "通过name取用户信息", response = String.class, responseContainer = "List")
public BizResponse<String> sayHello(@ApiParam("姓名") String name) {
return ResponseUtil.getSuccessBizResponse(service.sayHello(name));
}
@Override
@ApiOperation(value = "根据用户Id获取信息", notes = "根据用户Id获取信息", response = UserDto.class)
public UserDto getByid(Long id) {
return service.getById(id);
}
}
# Spring boot application
spring.application.name=dubbo-sample-springboot
##\u6307\u5B9A\u8FD0\u884C\u73AF\u5883\uFF0C\u975E\u5FC5\u586B\u3002\u6CE8\u610F\u53EA\u6709value=dev|test\uFF0C\u5E76\u4E14\u63A5\u5165\u914D\u7F6E\u4E2D\u5FC3\u6216\u8005\u8FD0\u884C\u65F6VM\u53C2\u6570\u8FFD\u52A0-Denv=dev|test,\u624D\u80FD\u751F\u6210swaager\u6587\u6863
spring.profiles.active=dev
# Base packages to scan Dubbo Component: @org.apache.dubbo.config.annotation.Service
## \u626B\u63CF\u6CE8\u89E3\u7C7B
dubbo.scan.base-packages=com.secoo.mall.dubbo.provider
# Dubbo Application
##dubbo\u5E94\u7528\u540D\u79F0\uFF0C\u975E\u5FC5\u586B\uFF0C\u9ED8\u8BA4\u4E3A${spring.application.name}
# dubbo.application.name=
##Dubbo Protocol
dubbo.protocol.name=dubbo
dubbo.protocol.port=12345
dubbo.registry.address=zookeeper://127.0.0.1:2181
##\u914D\u7F6Ezk\u96C6\u7FA4\u65B9\u5F0F
#dubbo.registry.address=zookeeper://dev01-zk-mall1.secoolocal.com:2181?backup=dev01-zk-mall2.secoolocal.com:2181,dev01-zk-mall3.secoolocal.com:2181
##\u7981\u7528\u9ED8\u8BA4ExceptionFilter\uFF0C\u542F\u7528\u81EA\u5B9A\u4E49responseExcepiton
dubbo.provider.filter=-exception,responseException
###set log levels###
log4j.rootLogger=info, stdout
###output to the console###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy HH:mm:ss:SSS z}] %t %5p %c{2}: %m%n
\ No newline at end of file
......@@ -10,6 +10,11 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-dubbo-springboot</artifactId>
<packaging>pom</packaging>
<modules>
<module>matrix-sample-dubbo-springboot-c</module>
<module>matrix-sample-dubbo-springboot-p</module>
</modules>
</project>
\ No newline at end of file
......@@ -15,7 +15,22 @@
<module>matrix-sample-dubbo-api</module>
<module>matrix-sample-dubbo-spring</module>
<module>matrix-sample-dubbo-springboot</module>
<module>matrix-sample-dubbo-biz</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-sample-dubbo-api</artifactId>
<version>1.3.2.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-sample-dubbo-biz</artifactId>
<version>1.3.2.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>matrix-sample-hbase</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-hbase-biz</artifactId>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>matrix-sample-hbase</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-hbase-starter</artifactId>
<dependencies>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-sample-hbase-starter</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>matrix-sample</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-hbase</artifactId>
<packaging>pom</packaging>
<modules>
<module>matrix-sample-hbase-biz</module>
<module>matrix-sample-hbase-springboot</module>
</modules>
</project>
\ No newline at end of file
......@@ -7,6 +7,7 @@
<modules>
<module>matrix-sample-xxl</module>
<module>matrix-sample-dubbo</module>
<module>matrix-sample-hbase</module>
</modules>
<parent>
<groupId>com.secoo.mall</groupId>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment