提交 209d7b7e 编写于 作者: M MaxKey

WebContext -> JpaWebContext

上级 aa2b0548
......@@ -28,7 +28,7 @@ import org.apache.mybatis.jpa.PageResultsSqlCache;
import org.apache.mybatis.jpa.util.BeanUtil;
import org.apache.mybatis.jpa.util.InstanceUtil;
import org.apache.mybatis.jpa.util.StringUtils;
import org.apache.mybatis.jpa.util.WebContext;
import org.apache.mybatis.jpa.util.JpaWebContext;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.github.benmanes.caffeine.cache.Cache;
......@@ -113,7 +113,7 @@ public class JpaBaseService <T extends JpaBaseEntity> {
if(mapper == null) {
String mapperClassBean = mapperClass.toLowerCase().charAt(0) + mapperClass.substring(1);
_logger.info("mapperClass Bean is {}" , mapperClassBean);
mapper = (IJpaBaseMapper<T>) WebContext.getBean(mapperClassBean);
mapper = (IJpaBaseMapper<T>) JpaWebContext.getBean(mapperClassBean);
}
} catch(Exception e) {
_logger.error("getMapper Exception " , e);
......
/*
* Copyright [2021] [MaxKey of copyright http://www.maxkey.top]
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -19,7 +19,11 @@ package org.apache.mybatis.jpa.util;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.commons.lang.SystemUtils;
import org.joda.time.DateTime;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.support.WebApplicationContextUtils;
......@@ -32,7 +36,11 @@ import org.springframework.web.context.support.WebApplicationContextUtils;
* @author Crystal.Sea
* @since 1.6
*/
public final class WebContext {
public final class JpaWebContext {
private static String VERSION = null;
public static StandardEnvironment properties;
public static ApplicationContext applicationContext=null;
......@@ -119,5 +127,37 @@ public final class WebContext {
public static String getParameter(String name){
return getRequest().getParameter(name);
}
public static String version() {
if(VERSION == null) {
StringBuffer version =
new StringBuffer("---------------------------------------------------------------------------------\n");
version.append("+ MaxKey \n");
version.append("+ Single Sign On ( SSO ) \n");
version.append("+ Version ");
version.append(properties.getProperty("application.formatted-version")+"\n");
version.append("+\n");
version.append(String.format("+ %sCopyright 2018 - %s https://www.maxkey.top/\n",
(char)0xA9 , new DateTime().getYear()
));
version.append("+ Licensed under the Apache License, Version 2.0 \n");
version.append("---------------------------------------------------------------------------------\n");
version.append("+ JAVA \n");
version.append(String.format("+ %s java version %s, class %s\n",
SystemUtils.JAVA_VENDOR,
SystemUtils.JAVA_VERSION,
SystemUtils.JAVA_CLASS_VERSION
));
version.append(String.format("+ %s (build %s, %s)\n",
SystemUtils.JAVA_VM_NAME,
SystemUtils.JAVA_VM_VERSION,
SystemUtils.JAVA_VM_INFO
));
version.append("---------------------------------------------------------------------------------\n");
VERSION = version.toString();
}
return VERSION;
}
}
......@@ -25,7 +25,7 @@ import java.util.List;
import org.apache.mybatis.jpa.test.dao.service.StudentsService;
import org.apache.mybatis.jpa.test.entity.Students;
import org.apache.mybatis.jpa.util.WebContext;
import org.apache.mybatis.jpa.util.JpaWebContext;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
......@@ -227,7 +227,7 @@ public class MyBatisTestRunner {
_logger.info("Application dir "+System.getProperty("user.dir"));
context = new ClassPathXmlApplicationContext(new String[] {"spring/applicationContext.xml"});
WebContext.applicationContext=context;
service =(StudentsService)WebContext.getBean("studentsService");
JpaWebContext.applicationContext=context;
service =(StudentsService)JpaWebContext.getBean("studentsService");
}
}
\ No newline at end of file
......@@ -21,7 +21,7 @@ import org.apache.mybatis.jpa.id.SerialGenerator;
import org.apache.mybatis.jpa.persistence.JpaPageResults;
import org.apache.mybatis.jpa.test.dao.service.StudentsService;
import org.apache.mybatis.jpa.test.entity.Students;
import org.apache.mybatis.jpa.util.WebContext;
import org.apache.mybatis.jpa.util.JpaWebContext;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -59,7 +59,7 @@ public class MybatisJpaApplication implements ApplicationRunner{
@Override
public void run(ApplicationArguments args) throws Exception {
WebContext.applicationContext=applicationContext;
JpaWebContext.applicationContext=applicationContext;
_logger.info("queryPageResults by mapperId...");
Students student=new Students();
......
......@@ -21,7 +21,7 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.mybatis.jpa.test.dao.service.StudentsService;
import org.apache.mybatis.jpa.test.entity.Students;
import org.apache.mybatis.jpa.util.WebContext;
import org.apache.mybatis.jpa.util.JpaWebContext;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -50,7 +50,7 @@ public class MybatisJpaApplicationTest{
@Before
public void before() {
_logger.info("---------------- before");
WebContext.applicationContext=applicationContext;
JpaWebContext.applicationContext=applicationContext;
}
......
......@@ -24,7 +24,7 @@ import java.util.List;
import org.apache.mybatis.jpa.test.dao.service.StudentsService;
import org.apache.mybatis.jpa.test.entity.Students;
import org.apache.mybatis.jpa.util.WebContext;
import org.apache.mybatis.jpa.util.JpaWebContext;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
......@@ -161,8 +161,8 @@ public class MyBatisTestRunner {
_logger.info("Application dir "+System.getProperty("user.dir"));
context = new ClassPathXmlApplicationContext(new String[] {"spring/applicationContext.xml"});
WebContext.applicationContext=context;
service =(StudentsService)WebContext.getBean("studentsService");
JpaWebContext.applicationContext=context;
service =(StudentsService)JpaWebContext.getBean("studentsService");
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册