Commit feed76f0 by manxiaoqiang

大后台

parents
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
This diff is collapsed. Click to expand it.
package common;
/**
* Created by sunhao on 17/8/1.
* desc:app平台类型
*/
public enum RoleEnum {
MANAGER(1L,"管理员"),
SUB_APP_MANAGER(2L,"子应用管理员"),
CUSTOM_AUTH(3L,"自定义权限"),
CUSTOM_ROLE(4L,"自定义角色"),
CHANNEL_PERSON(5L,"渠道账号");
private Long key;
private String value;
RoleEnum(Long key, String value) {
this.key = key;
this.value = value;
}
public Long getKey() {
return key;
}
public String getValue() {
return value;
}
}
package common.controller;
import common.model.Menu;
import common.model.User;
import common.repository.MenuRepository;
import common.repository.UserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import util.ResultModel;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
@Controller
@RequestMapping("login")
public class LoginController {
protected Logger logger = LoggerFactory.getLogger(LoginController.class);
@Autowired
private UserRepository userRepository;
@RequestMapping(value = "login", method = RequestMethod.GET)
@ResponseBody
public ResultModel login(HttpServletResponse response, @RequestParam String email, @RequestParam String password) {
User user = userRepository.login(email, password);
if(null != user){
Cookie cookie = new Cookie("TOKEN", user.getId().toString());
cookie.setPath("/");
cookie.setMaxAge(60 * 60 * 24 * 7);
response.addCookie(cookie);
return ResultModel.OK(true);
}
return ResultModel.OK(false);
}
}
package common.controller;
import common.model.Menu;
import common.model.User;
import common.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import security.annotation.CurrentAccount;
import util.ResultModel;
import java.util.List;
/**
* Created by mxq on 17/12/21.
* 优先测试账号查询
*/
@Controller
@RequestMapping("menu")
public class MenuController {
@Autowired
private MenuService menuService;
@RequestMapping(value = "find", method = RequestMethod.GET)
@ResponseBody
public ResultModel findAll(@CurrentAccount User loginAccount) {
List<Menu> menus = menuService.listAll();
return ResultModel.OK(menus);
}
}
package common.controller;
import common.model.Menu;
import common.model.User;
import common.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import security.annotation.CurrentAccount;
import util.ResultModel;
import java.util.List;
/**
* Created by mxq on 2017/12/21.
*/
@Controller
@RequestMapping("user")
public class UserController {
@Autowired
private User menuService;
@RequestMapping(value = "find", method = RequestMethod.GET)
@ResponseBody
public ResultModel findAll(@CurrentAccount User loginAccount) {
List<Menu> menus = menuService.listAll();
return ResultModel.OK(menus);
}
}
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Date;
@Entity
public class Auth {
private Long id;
private Long user;
private String auth;
private String modifyAccountName;
private String createAccountName;
private Date modifyTime;
private Date createTime;
private Boolean delFlag;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getUser() {
return user;
}
public void setUser(Long user) {
this.user = user;
}
public String getAuth() {
return auth;
}
public void setAuth(String auth) {
this.auth = auth;
}
public String getModifyAccountName() {
return modifyAccountName;
}
public void setModifyAccountName(String modifyAccountName) {
this.modifyAccountName = modifyAccountName;
}
public String getCreateAccountName() {
return createAccountName;
}
public void setCreateAccountName(String createAccountName) {
this.createAccountName = createAccountName;
}
public Date getModifyTime() {
return modifyTime;
}
public void setModifyTime(Date modifyTime) {
this.modifyTime = modifyTime;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Boolean getDelFlag() {
return delFlag;
}
public void setDelFlag(Boolean delFlag) {
this.delFlag = delFlag;
}
@Override
public String toString() {
return "Auth{" +
"id=" + id +
", user=" + user +
", auth='" + auth + '\'' +
", modifyAccountName='" + modifyAccountName + '\'' +
", createAccountName='" + createAccountName + '\'' +
", modifyTime=" + modifyTime +
", createTime=" + createTime +
", delFlag=" + delFlag +
'}';
}
}
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Transient;
import java.util.List;
@Entity
public class Menu {
private Long id;
// 授权处显示的名字
private String name;
// 对应的参数
private String menu;
private int orderIndex;
private Long parent;
private List<Menu> sons;
public Menu() {
super();
}
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMenu() {
return menu;
}
public void setMenu(String menu) {
this.menu = menu;
}
public Long getParent() {
return parent;
}
public void setParent(Long parent) {
this.parent = parent;
}
public int getOrderIndex() {
return orderIndex;
}
public void setOrderIndex(int orderIndex) {
this.orderIndex = orderIndex;
}
@Transient
public List<Menu> getSons() {
return sons;
}
public void setSons(List<Menu> sons) {
this.sons = sons;
}
@Override
public String toString() {
return "Menu{" +
"id=" + id +
", name='" + name + '\'' +
", menu='" + menu + '\'' +
", orderIndex=" + orderIndex +
", parent='" + parent + '\'' +
'}';
}
}
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class RoleType {
private Long id;
//
private String position;
public RoleType() {
super();
}
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
}
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Transient;
import java.util.Date;
import java.util.List;
@Entity
public class User {
private Long id;
private String email;
private String password;
private String name;
private Long role;
private Long roleType;
private String modifyAccountName;
private String createAccountName;
private Date modifyTime;
private Date createTime;
private Boolean delFlag;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getRole() {
return role;
}
public void setRole(Long role) {
this.role = role;
}
public Long getRoleType() {
return roleType;
}
public void setRoleType(Long roleType) {
this.roleType = roleType;
}
public String getModifyAccountName() {
return modifyAccountName;
}
public void setModifyAccountName(String modifyAccountName) {
this.modifyAccountName = modifyAccountName;
}
public String getCreateAccountName() {
return createAccountName;
}
public void setCreateAccountName(String createAccountName) {
this.createAccountName = createAccountName;
}
public Date getModifyTime() {
return modifyTime;
}
public void setModifyTime(Date modifyTime) {
this.modifyTime = modifyTime;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Boolean getDelFlag() {
return delFlag;
}
public void setDelFlag(Boolean delFlag) {
this.delFlag = delFlag;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", email='" + email + '\'' +
", password='" + password + '\'' +
", name='" + name + '\'' +
", role=" + role +
", roleType=" + roleType +
", modifyAccountName='" + modifyAccountName + '\'' +
", createAccountName='" + createAccountName + '\'' +
", modifyTime=" + modifyTime +
", createTime=" + createTime +
", delFlag=" + delFlag +
'}';
}
}
package common.repository;
import common.model.Menu;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Transactional
public interface MenuRepository extends JpaRepository<Menu, Long> {
@Query(value="select * from menu where parent <> 0",nativeQuery=true)
List<Menu> listAllSonMenu();
@Query(value="select * from menu where parent = 0",nativeQuery=true)
List<Menu> listAllParentMenu();
@Query(value="select * from menu where id in ?1",nativeQuery=true)
List<Menu> listMenuByIds(List<String> idList);
}
package common.repository;
import common.model.Menu;
import common.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Transactional
public interface UserRepository extends JpaRepository<User, Long> {
@Query(value="select * from User where email = ?1 and password = ?2",nativeQuery=true)
User login(String email, String pwd);
@Query(value="select * from User where id = ?1",nativeQuery=true)
User findOne(Long id);
}
package common.service;
import common.model.Menu;
import java.util.List;
/**
* Created by mxq on 2017/12/21.
*/
public interface MenuService {
List<Menu> listAll();
}
package common.service;
import common.model.Menu;
import common.model.User;
import java.util.List;
/**
* Created by mxq on 2017/12/21.
*/
public interface UserService {
User create(User login, User resource);
}
package common.service.impl;
import common.model.Menu;
import common.repository.MenuRepository;
import common.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by mxq on 2017/12/21.
*/
@Service
public class MenuServiceImpl implements MenuService {
@Autowired
private MenuRepository menuRepository;
@Override
public List<Menu> listAll() {
List<Menu> result = new ArrayList<>();
List<Menu> parentMenuList = menuRepository.listAllParentMenu();
List<Menu> menuList = menuRepository.listAllSonMenu();
Map<Long, List<Menu>> map = new HashMap<>();
for(Menu m : menuList){
if(map.containsKey(m.getParent())){
List<Menu> list = map.get(m.getParent());
list.add(m);
map.put(m.getParent(),list);
} else{
List<Menu> list = new ArrayList<>();
list.add(m);
map.put(m.getParent(), list);
}
}
for(Menu m : parentMenuList){
m.setSons(map.get(m.getId()));
result.add(m);
}
return result;
}
}
package common.service.impl;
import common.model.Menu;
import common.model.User;
import common.repository.MenuRepository;
import common.service.MenuService;
import common.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by mxq on 2017/12/21.
*/
@Service
public class UserServiceImpl implements UserService {
@Autowired
private MenuRepository menuRepository;
@Override
public User create(User login, User resource) {
if(login.getRole().equals("")){
} else{
}
return null;
}
}
package exception;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import util.ResultModel;
import util.ResultStatus;
/**
* Created by nolan on 18/11/2016.
* description:
*/
@ControllerAdvice
public class GlobalExceptionAdvice {
private Logger logger = LoggerFactory.getLogger(GlobalExceptionAdvice.class);
@ExceptionHandler(TransferCurrentAccountException.class)
public ResponseEntity<ResultModel> handleTransferCurrentAccountException(TransferCurrentAccountException ex) {
logger.error("handleTransferCurrentAccountException......", ex);
// ex.printStackTrace();
return new ResponseEntity<ResultModel>(ResultModel.ERROR(ResultStatus.USERNAME_LOGIN_EXPIRE), HttpStatus.OK);
}
@ExceptionHandler(TipException.class)
public ResponseEntity<ResultModel> handleTipException(TipException ex) {
logger.error("handleTipException......", ex);
ex.printStackTrace();
return new ResponseEntity<ResultModel>(new ResultModel(-999, ex.getMessage()), HttpStatus.OK);
}
@ExceptionHandler(RuntimeException.class)
public ResponseEntity<ResultModel> handleRuntimeException(RuntimeException ex) {
logger.error("handleRuntimeException......", ex);
ex.printStackTrace();
return new ResponseEntity<ResultModel>(new ResultModel(-999, ex.getMessage()), HttpStatus.EXPECTATION_FAILED);
}
@ExceptionHandler(Exception.class)
public ResponseEntity<ResultModel> handleAllException(Exception ex) {
logger.error("handleAllException......", ex);
ex.printStackTrace();
return new ResponseEntity<ResultModel>(new ResultModel(-999, ex.getMessage()), HttpStatus.EXPECTATION_FAILED);
}
}
package exception;
public class NotFoundException extends RuntimeException {
/**
*
*/
private static final long serialVersionUID = 1L;
public NotFoundException() {
super();
}
public NotFoundException(final String message) {
super(message);
}
public NotFoundException(final String message, final Throwable cause) {
super(message, cause);
}
public NotFoundException(final Throwable cause) {
super(cause);
}
}
package exception;
/**
* Created by nolan on 24/11/2016.
* description:
*/
public class TipException extends RuntimeException {
public TipException() {
}
public TipException(String message) {
super(message);
}
public TipException(String message, Throwable cause) {
super(message, cause);
}
public TipException(Throwable cause) {
super(cause);
}
public TipException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
package exception;
/**
* Created by nolan on 18/11/2016.
* description:
*/
public class TransferCurrentAccountException extends RuntimeException {
}
package security.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Authorization {
String description() default "";
}
\ No newline at end of file
package security.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Created by nolan on 11/11/2016.
* description:
*/
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface CurrentAccount {
}
package security.interceptor;
import common.model.User;
import common.repository.UserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class AuthorizationInterceptor extends HandlerInterceptorAdapter {
private static final Logger logger = LoggerFactory.getLogger(AuthorizationInterceptor.class);
//存放鉴权信息的Header名称,默认是Authorization
public static String httpHeaderName = "Authorization";
@Autowired
private UserRepository userRepository;
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
//放开登录
if (request.getRequestURL().indexOf("login/login") != -1){
return true;
}
String token = request.getHeader(httpHeaderName);
System.out.println(token);
String id = getCookieToken(request.getCookies(), "TOKEN");
if(null != id){
User account = userRepository.findOne(Long.parseLong(id));
User sessionAct = (User) request.getSession().getAttribute("$CURRENT_ACCOUNT$");
if (sessionAct == null || !account.getId().equals(sessionAct.getId())) {
request.getSession().setAttribute("$CURRENT_ACCOUNT$", account);
}
return true;
}
return false;
}
private String getCookieToken(Cookie[] cookies, String name){
String token = null;
if (null != cookies) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals(name)) {
token = cookie.getValue();
}
}
}
return token;
}
}
\ No newline at end of file
package security.resolvers;
import common.model.User;
import common.repository.UserRepository;
import exception.TransferCurrentAccountException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.MethodParameter;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;
import security.annotation.CurrentAccount;
import javax.servlet.http.HttpServletRequest;
/**
* Created by nolan on 11/11/2016.
* description:
*/
@Component
public class LoginUserMethodArgumentsResolver implements HandlerMethodArgumentResolver {
@Autowired
private UserRepository accountRepository;
@Override
public boolean supportsParameter(MethodParameter parameter) {
return parameter.getParameterType().isAssignableFrom(User.class) && parameter.hasParameterAnnotation(CurrentAccount.class);
}
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
HttpServletRequest nativeRequest = (HttpServletRequest) webRequest.getNativeRequest();
Object currentAct = nativeRequest.getSession().getAttribute("$CURRENT_ACCOUNT$");
if (currentAct != null) {
return currentAct;
}
throw new TransferCurrentAccountException();
}
}
package util;
/**
* Created by nolan on 15/11/2016.
* description:
*/
public class ResultModel {
/**
* 返回码
*/
private int code;
/**
* 返回结果描述
*/
private String message;
/**
* 返回内容
*/
private Object content;
public ResultModel(int code, String message) {
this.code = code;
this.message = message;
this.content = "";
}
public ResultModel(int code, String message, Object content) {
this.code = code;
this.message = message;
this.content = content;
}
public ResultModel(ResultStatus status) {
this.code = status.getCode();
this.message = status.getMessage();
this.content = "";
}
public ResultModel(ResultStatus status, Object content) {
this.code = status.getCode();
this.message = status.getMessage();
this.content = content;
}
public static ResultModel OK(Object content) {
return new ResultModel(ResultStatus.SUCCESS, content);
}
public static ResultModel OK() {
return new ResultModel(ResultStatus.SUCCESS);
}
public static ResultModel ERROR(ResultStatus error) {
return new ResultModel(error);
}
public int getCode() {
return code;
}
public String getMessage() {
return message;
}
public Object getContent() {
return content;
}
}
\ No newline at end of file
package util;
/**
* Created by nolan on 15/11/2016.
* description:
*/
public enum ResultStatus {
SUCCESS(200, "成功"),
FAILED(-200, "失败"),
NUMBER_LIMIT(-300, "超过限定值,无法添加"),
NETWORK_ERROR(404, "网络异常"),
PARAM_INVALID(-1000, "参数错误"),
USERNAME_OR_PASSWORD_ERROR(-1001, "用户名或密码错误"),
USERNAME_LOGIN_EXPIRE(-1002, "用户登陆失效"),
SUB_ACCOUNT_DISABLE(-1003, "子帐号已禁用"),
ORIGINAL_ACCOUNT_DISABLE(-1004, "主体帐号已禁用"),
ACCOUNT_BUSINESS_EXPIRE(-1005, "主帐号已过期"),
ACCOUNT_NOT_CONFIRM(-1006, "帐号待审核"),
APP_DEL(-1007, "应用已被删除"),
AUTH_ACCOUNT_BUSINESS_EXPIRE(-1008, "授权帐号已过期"),
ONELINK_OCCUPY(-1009, "onelink占用推广活动"),
ACCOUNT_NOT_ACTIVATE(-1010, "账号未激活"),
USER_NOT_AUTH(-2000, "功能未授权"),
CAMPAIGN_CREATEING(-3000, "推广活动正在创建中, 请勿重复提交"),
ID_NOT_EXIST(-4000, "对应ID的记录不存在"),
EXPORT_DATA_EXIST(-5000, "导出记录已存在"),
EXPORT_FILE_EXIST(-5001, "导出文件不存在"),
RECORD_EXIST(-6000, "记录已存在,请勿重复提交"),
NAME_EXIST(-6001, "名称已存在"),
EVENT_NULL(-6002, "事件为空"),
FILE_TYPE_ERROR(-6003, "文件格式错误"),
CAMPAIGN_OCCUPY(-1010, "推广活动占用渠道"),
NAME_NULL(-1101, "名称为空"),
NAME_INVAILD(-1102, "名称不合法"),
CAMPAIGN_NOT_MATCH_APP(-1103, "推广活动与应用不匹配"),
SURL_NULL(-1105, "短链为空"),
CAMPAIGN_NULL(-1106, "推广活动不存在"),
CAMPAIGN_EXISTS(-1107, "此分包渠道的活动已存在"),
CAMPAIGN_REPEAT(-1008,"批量创建推广活动时名称重复"),
MSG_SMS_OUTOFTIME(-4001, "验证码过时,重新获取"),
MSG_SMS_REQUESTTIMES(-4002, "今天请求验证码次数过多"),
MSG_SMS_IPREQUESTTIMES(-4003, "IP地址请求过多"),
MSG_SMS_IPERROR(-4004, "未知ip达到峰值"),
MSG_SMS_WRONG(-4005, "验证码不正确"),
CHANNELACCOUNT_NOEXIST(-5001, "渠道帐号不存在"),
CHANNEL_ALIASNAME_EXIST(-5002, "该名称系统已存在"),
CHANNELACCOUNT_EXIST(-5003, "该账号ID已创建投放账号,不可重复创建"),
CHANNEL_LINKID_NOEXIST(-5004, "link_id不存在"),
COMMON_IP_EXISTS(-7000, "公共ip已存在"),
EXP_INVALID(11000, "自定义表达式错误");
/**
* 返回码
*/
private int code;
/**
* 返回结果描述
*/
private String message;
ResultStatus(int code, String message) {
this.code = code;
this.message = message;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"
default-lazy-init="true">
<description>调度配置</description>
<!-- <bean id="autoSyncSurlTask" class="com.reyun.task.AutoSyncSurlTask"></bean>-->
<!-- <task:scheduled-tasks>
&lt;!&ndash;//定时同步短链数据(每5分钟执行一次)&ndash;&gt;
<task:scheduled ref="autoSyncSurlTask" method="run" cron="0 */2 * * * ?"/>
</task:scheduled-tasks>-->
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:task="http://www.springframework.org/schema/task" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"
default-lazy-init="true">
<description>Spring公共配置</description>
<aop:aspectj-autoproxy proxy-target-class="true"/>
<context:component-scan base-package="tkio" />
<context:component-scan base-package="track" />
<context:component-scan base-package="common" />
<context:property-placeholder location="classpath:persistence.properties"/>
<bean id="parentDataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
<property name="driverClassName" value="${dataSource.driverClassName}"/>
<!-- 配置初始化大小、最小、最大 -->
<property name="initialSize" value="1"/>
<property name="minIdle" value="1"/>
<property name="maxActive" value="20"/>
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000"/>
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="300000"/>
</bean>
<bean id="dataSource" parent="parentDataSource">
<property name="url" value="${default.dataSource.url}"/>
<property name="username" value="${default.dataSource.username}"/>
<property name="password" value="${default.dataSource.password}"/>
</bean>
<!-- JPA实体管理工厂的配置 -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan" value="common.model">
</property>
<property name="persistenceUnitName" value="defaultUnit" />
<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/>
<property name="jpaProperties">
<props>
<prop key="hibernate.physical_naming_strategy">com.reyun.framework.strategy.ImprovedNamingStrategy
</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop><!-- none -->
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.use_sql_comments">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
</props>
</property>
</bean>
<!--指定实现JPA的适配器 -->
<bean id="hibernateJpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect"/>
</bean>
<!-- Jpa 事务配置 -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<!-- Spring Data Jpa配置 -->
<jpa:repositories base-package="common.repository"
repository-impl-postfix="Impl" transaction-manager-ref="transactionManager"
entity-manager-factory-ref="entityManagerFactory"/>
<!-- 使用annotation定义事务 -->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="report*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="list*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="query*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<tx:advice id="monitorTxAdvice" transaction-manager="monitorTransactionManager">
<tx:attributes>
<tx:method name="report*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="list*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="query*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<aop:config expose-proxy="true">
<aop:pointcut id="txPointcut" expression="execution(* common.service.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
</aop:config>
<!-- SpringMVC上传文件时,需要配置MultipartResolver处理器 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"/>
<!-- 指定所上传文件的总大小不能超过2000KB。注意maxUploadSize属性的限制不是针对单个文件,而是所有文件的容量之和 -->
<property name="maxUploadSize" value="2000000"/>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true">
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<Encoding>UTF-8</Encoding>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%-20(%d{HH:mm:ss.SSS} [%thread][line:%L]) %-5level %logger{80} %M - %msg%n</Pattern>
</layout>
</appender>
<logger name="org.springframework" level="warn"/>
<logger name="org.springframework.remoting" level="warn"/>
<logger name="org.springframework.scheduling.quartz" level="warn"/>
<logger name="org.springframework.data.jpa" level="warn"/>
<logger name="ch.qos.logback" level="warn"/>
<logger name="org.hibernate" level="warn"/>
<root level="info">
<appender-ref ref="stdout" />
</root>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true">
<appender name="infoFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<Encoding>UTF-8</Encoding>
<file>/data/logs/trackingio.com/trackingio.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>/data/logs/trackingio.com/trackingio.%d{yyyy-MM-dd}.log.zip</FileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%-20(%d{HH:mm:ss.SSS} [%thread][line:%L]) %-5level %logger{80} - %msg%n</pattern>
</layout>
</appender>
<logger name="org.springframework">
<level value="warn" />
</logger>
<logger name="org.hibernate">
<level value="warn" />
</logger>
<logger name="org.apache.phoenix">
<level value="warn" />
</logger>
<logger name="org.apache.zookeeper">
<level value="warn" />
</logger>
<logger name="org.apache.hadoop">
<level value="warn" />
</logger>
<logger name="org.elasticsearch.plugins">
<level value="warn" />
</logger>
<root level="info">
<appender-ref ref="infoFile" />
<appender-ref ref="cat" />
</root>
</configuration>
\ No newline at end of file
dataSource.driverClassName=${datasource.driver}
default.dataSource.url=${default.datasource.url}
default.dataSource.username=${default.datasource.username}
default.dataSource.password=${default.datasource.password}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<context:component-scan base-package="exception" />
<context:component-scan base-package="common.controller" />
<context:component-scan base-package="track.controller" />
<context:component-scan base-package="tkio.controller" />
<mvc:annotation-driven>
<mvc:argument-resolvers>
<bean class="security.resolvers.LoginUserMethodArgumentsResolver"></bean>
</mvc:argument-resolvers>
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg value="UTF-8" />
</bean>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**" />
<bean class="security.interceptor.AuthorizationInterceptor" />
</mvc:interceptor>
</mvc:interceptors>
</beans>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0" metadata-complete="true">
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>ch.qos.logback.ext.spring.web.LogbackConfigListener</listener-class>
</listener>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>logbackConfigLocation</param-name>
<param-value>classpath:/logback.xml</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/applicationContext*.xml</param-value>
</context-param>
<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:rest-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/home.html</welcome-file>
</welcome-file-list>
</web-app>
\ No newline at end of file
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
</web-app>
\ 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