Commit bee8a2ac authored by Quxl's avatar Quxl

第一次提交

parents
/target/
/.settings/
.classpath
.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>
<groupId>com.egolm</groupId>
<artifactId>shop</artifactId>
<version>0.0.1-SNAPSHOT</version>
<description>B2B前端接口</description>
<properties>
<start-class>com.egolm.shop.ShopApplication</start-class>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.38</version>
</dependency>
<dependency>
<groupId>com.egolm</groupId>
<artifactId>common</artifactId>
<version>0.0.1-RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.6</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>${start-class}</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>my</id>
<name>my</name>
<url>http://git.egolm.com:9003/nexus/content/groups/public/</url>
</repository>
<repository>
<id>repo1</id>
<name>repo1</name>
<url>http://repo1.maven.org/maven2/</url>
</repository>
<repository>
<id>mvnrepository</id>
<name>mvnrepository</name>
<url>http://mvnrepository.com/</url>
</repository>
</repositories>
</project>
\ No newline at end of file
package cn.ossip.shop;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableCaching
@EnableSwagger2
@SpringBootApplication
@EnableTransactionManagement
public class ShopApplication {
private static ApplicationContext applicationContext;
public static void main(String[] args) {
applicationContext = SpringApplication.run(ShopApplication.class, args);
}
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
public static Object getBean(String name){
return getApplicationContext().getBean(name);
}
public static <T> T getBean(Class<T> clazz){
return getApplicationContext().getBean(clazz);
}
public static <T> T getBean(String name, Class<T> clazz){
return getApplicationContext().getBean(name, clazz);
}
}
package cn.ossip.shop.config;
import javax.sql.DataSource;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import com.alibaba.druid.pool.DruidDataSource;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.jdbc.dialect.MySqlDialect;
@Configuration
public class DataSourceConfig {
@Bean
@Primary
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource getDataSource() {
return DataSourceBuilder.create().type(DruidDataSource.class).build();
}
@Bean
@Primary
public PlatformTransactionManager getTransactionManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Bean
@Primary
public JdbcTemplate getJdbcTemplate(DataSource dataSource) {
JdbcTemplate jdbcTemplate = new JdbcTemplate();
jdbcTemplate.setDataSource(dataSource);
jdbcTemplate.setDialect(new MySqlDialect());
jdbcTemplate.setSql_level(3);
return jdbcTemplate;
}
}
\ No newline at end of file
package cn.ossip.shop.config;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
import com.egolm.common.bean.Rjx;
@Component
public class ExceptionHandler implements HandlerExceptionResolver {
private static final Log logger = LogFactory.getLog(ExceptionHandler.class);
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
ModelAndView mav = new ModelAndView(new MappingJackson2JsonView());
try {
response.setContentType("application/json");
if (ex instanceof XException) {
mav.addAllObjects(((XException) ex).getRjx());
} else {
mav.addAllObjects(Rjx.jsonErr().setMessage("未处理异常[" + ex.getClass().getName() + ":" + ex.getMessage() + "]"));
}
} catch (Exception e) {
mav.addAllObjects(Rjx.jsonErr().setMessage("异常处理失败"));
} finally {
logger.error("", ex);
}
return mav;
}
}
package cn.ossip.shop.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
@Configuration
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.egolm.shop"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("在线文档")
.description("在线文档")
.termsOfServiceUrl("NO terms of service")
.version("1.0")
.build();
}
}
package cn.ossip.shop.config;
import java.util.EventListener;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestContextListener;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setUseSuffixPatternMatch(false).setUseTrailingSlashMatch(false);
}
@Bean
public ServletListenerRegistrationBean<EventListener> getDemoListener(){
ServletListenerRegistrationBean<EventListener> registrationBean = new ServletListenerRegistrationBean<>();
registrationBean.setListener(new RequestContextListener());
return registrationBean;
}
public static HttpServletRequest getRequest() {
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
if(servletRequestAttributes != null) {
return servletRequestAttributes.getRequest();
}
return null;
}
public static HttpServletResponse getResponse() {
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
if(servletRequestAttributes != null) {
return servletRequestAttributes.getResponse();
}
return null;
}
public static HttpSession getSession() {
HttpServletRequest request = WebMvcConfig.getRequest();
if(request != null) {
return request.getSession();
}
return null;
}
}
package cn.ossip.shop.config;
import com.egolm.common.bean.Rjx;
public class XException extends RuntimeException {
private static final long serialVersionUID = 1L;
private Rjx rjx = Rjx.jsonErr().setStatus(500).setMessage("ERROR");
public XException(String msg) {
super(msg);
rjx.setMessage(msg);
}
public XException(String msg, Throwable e) {
super(msg, e);
rjx.setMessage(msg);
}
public XException(String msg, int code) {
super(msg);
rjx.setMessage(msg);
rjx.setStatus(code);
}
public XException(String msg, int code, Throwable e) {
super(msg, e);
rjx.setMessage(msg);
rjx.setStatus(code);
}
public Rjx getRjx() {
return rjx;
}
public static void assertNotBlank(Object obj, String message) {
if(obj == null || obj.toString().trim().equals("")) {
throw new XException((message == null || message.trim().equals("")) ? "对象不能为空" : message);
}
}
}
server.tomcat.max-threads=1000
server.tomcat.min-spare-threads=30
server.port=8087
server.context-path=/
server.session.timeout=90000
server.tomcat.uri-encoding=utf-8
spring.http.multipart.maxFileSize=5MB
spring.http.multipart.maxRequestSize=5MB
spring.http.encoding.force=true
spring.http.encoding.enabled=true
spring.http.encoding.charset=utf-8
spring.datasource.username=sa
spring.datasource.password=qiyang
spring.datasource.url=jdbc:sqlserver://10.10.0.51:56443;instanceName=SQLSERVER;DatabaseName=EGOLMSAAS
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.testWhileIdle=true
spring.datasource.validationQuery=SELECT 1
spring.datasource.timeBetweenEvictionRunsMillis=3600000
\ No newline at end of file
server.tomcat.max-threads=1000
server.tomcat.min-spare-threads=30
server.port=8087
server.context-path=/
server.session.timeout=90000
server.tomcat.uri-encoding=utf-8
spring.http.multipart.maxFileSize=5MB
spring.http.multipart.maxRequestSize=5MB
spring.http.encoding.force=true
spring.http.encoding.enabled=true
spring.http.encoding.charset=utf-8
spring.datasource.username=sa
spring.datasource.password=qiyang
spring.datasource.url=jdbc:sqlserver://10.10.0.51:56443;instanceName=SQLSERVER;DatabaseName=EGOLMSAAS
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.testWhileIdle=true
spring.datasource.validationQuery=SELECT 1
spring.datasource.timeBetweenEvictionRunsMillis=3600000
server.tomcat.max-threads=1000
server.tomcat.min-spare-threads=30
server.port=8087
server.context-path=/
server.session.timeout=90000
server.tomcat.uri-encoding=utf-8
spring.http.multipart.maxFileSize=5MB
spring.http.multipart.maxRequestSize=5MB
spring.http.encoding.force=true
spring.http.encoding.enabled=true
spring.http.encoding.charset=utf-8
spring.datasource.username=sa
spring.datasource.password=qiyang
spring.datasource.url=jdbc:sqlserver://10.10.0.51:56443;instanceName=SQLSERVER;DatabaseName=EGOLMSAAS
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.testWhileIdle=true
spring.datasource.validationQuery=SELECT 1
spring.datasource.timeBetweenEvictionRunsMillis=3600000
spring.profiles.active=dev
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
updateCheck="false">
<defaultCache
eternal="false"
maxElementsInMemory="1000"
overflowToDisk="false"
diskPersistent="false"
timeToIdleSeconds="0"
timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LRU" />
</ehcache>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="LOG_BASE_PATH" value="/data/logs/shop" />
<include resource="org/springframework/boot/logging/logback/base.xml" />
<logger name="org" level="INFO" />
<logger name="com" level="INFO" />
<logger name="com.egolm" level="DEBUG" />
<appender name="siftingAppender" class="ch.qos.logback.classic.sift.SiftingAppender">
<discriminator>
<key>CTX_PATH</key>
<DefaultValue>shop</DefaultValue>
</discriminator>
<sift>
<appender name="rollingFileAppender"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${LOG_BASE_PATH}/${CTX_PATH}-%d{yyyy-MM-dd}.log</FileNamePattern>
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</encoder>
</appender>
</sift>
</appender>
<root level="INFO">
<appender-ref ref="siftingAppender" />
</root>
</configuration>
\ No newline at end of file
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