標籤:des style color io os ar 使用 java for
4 手動整合 1. 添加依賴
application層添加業務日誌介面模組依賴
<dependency>
<groupId>org.openkoala.businesslog</groupId>
<artifactId>koala-businesslog-api</artifactId>
<version>4.0.0</version>
</dependency>
web層添加業務日誌實現模組依賴
<dependency>
<groupId>org.openkoala.businesslog</groupId>
<artifactId>koala-businesslog-impl</artifactId>
<version>4.0.0</version>
</dependency>
2. 建立LogFilter類
例如com.xiaokaceng.demo.web.controller.businesslog.LogFilter.java
package com.xiaokaceng.demo.web.controller.businesslog;import org.openkoala.businesslog.utils.BusinessLogServletFilter;import javax.servlet.*;public class LogFilter extends BusinessLogServletFilter { /** * 將需要用到的資訊放入日誌上下文 * @param req * @param resp * @param chain */ @Override public void beforeFilter(ServletRequest req, ServletResponse resp, FilterChain chain) { addIpContext(getIp(req)); // TODO 需要自己實現擷取使用者名稱 addUserContext("xxx"); } public void init(FilterConfig filterConfig) throws ServletException { //To change body of implemented methods use File | Settings | File Templates. } public void destroy() { //To change body of implemented methods use File | Settings | File Templates. }}
注意:目前使用者需根據系統實現來擷取
3. 建立DefaultBusinessLogController類
package com.xiaokaceng.demo.web.controller.businesslog; import java.util.HashMap;import java.util.Map;import org.dayatang.domain.InstanceFactory;import org.dayatang.utils.Page;import org.openkoala.businesslog.application.BusinessLogApplication;import org.openkoala.businesslog.model.DefaultBusinessLogDTO;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.ResponseBody; @Controller@RequestMapping("/log")public class DefaultBusinessLogController {private BusinessLogApplication businessLogApplication; @ResponseBody@RequestMapping("/list")public Page pageJson(DefaultBusinessLogDTO defaultBusinessLogDTO,@RequestParam int page, @RequestParam int pagesize) {Page<DefaultBusinessLogDTO> all = getBusinessLogApplication().pageQueryDefaultBusinessLog(defaultBusinessLogDTO, page,pagesize);return all;} @ResponseBody@RequestMapping("/delete")public Map<String, Object> delete(@RequestParam String ids) {Map<String, Object> result = new HashMap<String, Object>();String[] value = ids.split(",");Long[] idArrs = new Long[value.length];for (int i = 0; i < value.length; i++) {idArrs[i] = Long.parseLong(value[i]);}getBusinessLogApplication().removeDefaultBusinessLogs(idArrs);result.put("result", "success");return result;} @ResponseBody@RequestMapping("/get/{id}")public Map<String, Object> get(@PathVariable Long id) {Map<String, Object> result = new HashMap<String, Object>();result.put("data", getBusinessLogApplication().getDefaultBusinessLog(id));return result;} public BusinessLogApplication getBusinessLogApplication() {if (null == businessLogApplication) {businessLogApplication = InstanceFactory.getInstance(BusinessLogApplication.class);}return businessLogApplication;}} |
4. 配置web.xml
<filter> <filter-name>LogFilter</filter-name> <filter-class>com.xiaokaceng.demo.web.controller.businesslog.LogFilter</filter-class></filter><filter-mapping> <filter-name>LogFilter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>
5. 類路徑下建立koala-businesslog.properties
pointcut=execution(* org.openkoala.example.application.impl.*.*(..)) #日誌開關 kaola.businesslog.enable=true #日誌匯出器 businessLogExporter=org.openkoala.businesslog.utils.BusinessLogExporterImpl #資料庫設定 log.db.jdbc.driver=${db.jdbcDriver} log.db.jdbc.connection.url=${db.connectionURL} log.db.jdbc.username=${db.username} log.db.jdbc.password=${db.password} log.db.jdbc.dialect=${hibernate.dialect} log.hibernate.hbm2ddl.auto=${hibernate.hbm2ddl.auto} log.hibernate.show_sql=${hibernate.show_sql} log.db.Type=${db.Type} db.generateDdl=${generateDdl} log.maximumConnectionCount=3000 log.minimumConnectionCount=100 #線程池配置 #核心線程數 log.threadPool.corePoolSize=100 #最大線程數 log.threadPool.maxPoolSize=3000 #隊列最大長度 log.threadPool.queueCapacity=2000 #線程池維護線程所允許的空閑時間 log.threadPool.keepAliveSeconds=300 #線程池對拒絕任務(無線程可用)的處理策略 log.threadPool.rejectedExecutionHandler=java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy |
6. 添加掃描包路徑
persistence-context.xml的packagesToScan節點添加:
<value>org.openkoala.businesslog.model</value>
7. 引入Spring配置
db-context.xml添加配置:
<import resource="classpath*:koala-businesslog-shared-persistence.xml"></import>
root.xml添加配置:
<import resource="classpath*:koala-businesslog-aop.xml"></import>
8. 剩餘整合請參考使用教程
說明:
- 以後外掛程式會提供一鍵整合功能,無需手動整合
- 第三方項目整合較為複雜,有較多技術約束
Koala業務日誌系統手動整合