com.luoshu.open.id.IdUiViewAutoConfigure Maven / Gradle / Ivy
package com.luoshu.open.id;
import com.luoshu.open.id.ui.IdUiViewPermission;
import com.luoshu.open.id.ui.IdResourceServlet;
import com.luoshu.open.id.ui.controller.IdController;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.servlet.Servlet;
import javax.servlet.http.HttpServlet;
import javax.sql.DataSource;
/**
* @author inme
*/
@Configuration
public class IdUiViewAutoConfigure {
// public static final String DISABLE_UI = "_luoshu.config.dev.disable";
@ConditionalOnBean(IdUiViewPermission.class)
@Bean
public ServletRegistrationBean luoshuIdWebUi(IdUiViewPermission uiViewPermission ,
LuoshuIdProperties luoshuConfigProperties){
/* 这段代码在生产环境没有用,只是用于开发过程 .. 开始 */
/* String val = System.getProperty(DISABLE_UI);
if("true".equalsIgnoreCase(val)){
ServletRegistrationBean empty = new ServletRegistrationBean<>(new EmptyServlet());
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
empty.addUrlMappings("/" + uuid + "/*");
return empty;
}*/
/* 这段代码在生产环境没有用,只是用于开发过程 .. 结束 */
// 下面的代码才有用
String urlPrefix = luoshuConfigProperties.getUi().getUrlPrefix();
if(!urlPrefix.startsWith("/")){
urlPrefix = "/" + urlPrefix;
}
DataSource dataSource = SqlUtil.createOrGetDataSource(luoshuConfigProperties);
JdbcIdDao jdbcDao = new JdbcIdDao(dataSource);
IdController idController = new IdController(jdbcDao , uiViewPermission);
IdResourceServlet resourceServlet = new IdResourceServlet(urlPrefix , "/luoshu/id/html", idController);
ServletRegistrationBean bean = new ServletRegistrationBean(resourceServlet);
bean.addUrlMappings(urlPrefix + "/*");
bean.addUrlMappings("/html/idConfig/*");
return bean;
}
/**
* 这个 servlet 没什么用,是为了开发过程中方便调试开发用的
*/
private static class EmptyServlet extends HttpServlet {
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy