Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
guns-vip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenjunxiong
guns-vip
Commits
0342473e
Commit
0342473e
authored
May 21, 2017
by
fsn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
配置错误页面并整理配置文件
parent
2df97931
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
31 deletions
+84
-31
src/main/java/com/stylefeng/guns/GunsApplication.java
+6
-0
src/main/java/com/stylefeng/guns/GunsServletInitializer.java
+0
-27
src/main/java/com/stylefeng/guns/common/controller/GunsErrorView.java
+28
-0
src/main/java/com/stylefeng/guns/config/web/WebConfig.java
+50
-4
No files found.
src/main/java/com/stylefeng/guns/GunsApplication.java
View file @
0342473e
...
@@ -5,6 +5,12 @@ import org.slf4j.LoggerFactory;
...
@@ -5,6 +5,12 @@ import org.slf4j.LoggerFactory;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
/**
* SpringBoot方式启动类
*
* @author stylefeng
* @Date 2017/5/21 12:06
*/
@SpringBootApplication
@SpringBootApplication
public
class
GunsApplication
{
public
class
GunsApplication
{
...
...
src/main/java/com/stylefeng/guns/GunsServletInitializer.java
View file @
0342473e
...
@@ -20,33 +20,6 @@ import java.util.EnumSet;
...
@@ -20,33 +20,6 @@ import java.util.EnumSet;
*/
*/
public
class
GunsServletInitializer
extends
SpringBootServletInitializer
{
public
class
GunsServletInitializer
extends
SpringBootServletInitializer
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
GunsServletInitializer
.
class
);
@Override
public
void
onStartup
(
ServletContext
servletContext
)
throws
ServletException
{
//用来非Controller层获取HttpServletRequest
servletContext
.
addListener
(
RequestContextListener
.
class
);
servletContext
.
addListener
(
ConfigListener
.
class
);
logger
.
info
(
"初始化ConfigListener成功!"
);
//防止xss攻击的filter
FilterRegistration
.
Dynamic
xssFilter
=
servletContext
.
addFilter
(
"xssSqlFilter"
,
new
XssFilter
());
xssFilter
.
addMappingForUrlPatterns
(
EnumSet
.
of
(
DispatcherType
.
REQUEST
),
false
,
"/*"
);
logger
.
info
(
"初始化XssFilter成功!"
);
try
{
ServletRegistration
.
Dynamic
dynamic
=
servletContext
.
addServlet
(
"DruidStatView"
,
StatViewServlet
.
class
);
dynamic
.
addMapping
(
"/druid/*"
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"初始化druid监控出错!"
,
e
);
}
logger
.
info
(
"初始化DruidMonitor成功!"
);
super
.
onStartup
(
servletContext
);
}
@Override
@Override
protected
SpringApplicationBuilder
configure
(
SpringApplicationBuilder
builder
)
{
protected
SpringApplicationBuilder
configure
(
SpringApplicationBuilder
builder
)
{
return
builder
.
sources
(
GunsApplication
.
class
);
return
builder
.
sources
(
GunsApplication
.
class
);
...
...
src/main/java/com/stylefeng/guns/common/controller/GunsErrorView.java
0 → 100644
View file @
0342473e
package
com
.
stylefeng
.
guns
.
common
.
controller
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.servlet.View
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.Map
;
/**
* 错误页面的默认跳转
*
* @author fengshuonan
* @date 2017-05-21 11:34
*/
@Component
(
"error"
)
public
class
GunsErrorView
implements
View
{
@Override
public
String
getContentType
()
{
return
"text/html"
;
}
@Override
public
void
render
(
Map
<
String
,
?>
map
,
HttpServletRequest
httpServletRequest
,
HttpServletResponse
httpServletResponse
)
throws
Exception
{
httpServletRequest
.
getRequestDispatcher
(
"/global/error"
).
forward
(
httpServletRequest
,
httpServletResponse
);
}
}
src/main/java/com/stylefeng/guns/config/web/
SpringMvc
Config.java
→
src/main/java/com/stylefeng/guns/config/web/
Web
Config.java
View file @
0342473e
package
com
.
stylefeng
.
guns
.
config
.
web
;
package
com
.
stylefeng
.
guns
.
config
.
web
;
import
com.alibaba.druid.support.http.StatViewServlet
;
import
com.stylefeng.guns.core.beetl.BeetlConfiguration
;
import
com.stylefeng.guns.core.beetl.BeetlConfiguration
;
import
com.stylefeng.guns.core.listener.ConfigListener
;
import
com.stylefeng.guns.core.util.xss.XssFilter
;
import
org.beetl.ext.spring.BeetlSpringViewResolver
;
import
org.beetl.ext.spring.BeetlSpringViewResolver
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.boot.web.servlet.ServletListenerRegistrationBean
;
import
org.springframework.boot.web.servlet.ServletRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.web.
servlet.config.annotation.WebMvcConfigurerAdapt
er
;
import
org.springframework.web.
context.request.RequestContextListen
er
;
/**
/**
* spring mvc配置类
* spring mvc配置类
...
@@ -14,9 +20,11 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
...
@@ -14,9 +20,11 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
* @date 2016年11月12日 下午5:03:32
* @date 2016年11月12日 下午5:03:32
*/
*/
@Configuration
@Configuration
public
class
SpringMvcConfig
extends
WebMvcConfigurerAdapter
{
public
class
WebConfig
{
// beetl的配置
/**
* beetl的配置
*/
@Bean
(
initMethod
=
"init"
)
@Bean
(
initMethod
=
"init"
)
public
BeetlConfiguration
beetlConfiguration
()
{
public
BeetlConfiguration
beetlConfiguration
()
{
BeetlConfiguration
beetlConfiguration
=
new
BeetlConfiguration
();
BeetlConfiguration
beetlConfiguration
=
new
BeetlConfiguration
();
...
@@ -24,7 +32,9 @@ public class SpringMvcConfig extends WebMvcConfigurerAdapter {
...
@@ -24,7 +32,9 @@ public class SpringMvcConfig extends WebMvcConfigurerAdapter {
return
beetlConfiguration
;
return
beetlConfiguration
;
}
}
// beetl的视图解析器
/**
* beetl的视图解析器
*/
@Bean
@Bean
public
BeetlSpringViewResolver
beetlViewResolver
()
{
public
BeetlSpringViewResolver
beetlViewResolver
()
{
BeetlSpringViewResolver
beetlSpringViewResolver
=
new
BeetlSpringViewResolver
();
BeetlSpringViewResolver
beetlSpringViewResolver
=
new
BeetlSpringViewResolver
();
...
@@ -33,4 +43,40 @@ public class SpringMvcConfig extends WebMvcConfigurerAdapter {
...
@@ -33,4 +43,40 @@ public class SpringMvcConfig extends WebMvcConfigurerAdapter {
beetlSpringViewResolver
.
setOrder
(
0
);
beetlSpringViewResolver
.
setOrder
(
0
);
return
beetlSpringViewResolver
;
return
beetlSpringViewResolver
;
}
}
/**
* druidServlet注册
*/
@Bean
public
ServletRegistrationBean
druidServletRegistration
()
{
ServletRegistrationBean
registration
=
new
ServletRegistrationBean
(
new
StatViewServlet
());
registration
.
addUrlMappings
(
"/druid/*"
);
return
registration
;
}
/**
* xssFilter注册
*/
@Bean
public
FilterRegistrationBean
xssFilterRegistration
()
{
FilterRegistrationBean
registration
=
new
FilterRegistrationBean
(
new
XssFilter
());
registration
.
addUrlPatterns
(
"/*"
);
return
registration
;
}
/**
* RequestContextListener注册
*/
@Bean
public
ServletListenerRegistrationBean
<
RequestContextListener
>
requestContextListenerRegistration
(){
return
new
ServletListenerRegistrationBean
<
RequestContextListener
>(
new
RequestContextListener
());
}
/**
* ConfigListener注册
*/
@Bean
public
ServletListenerRegistrationBean
<
ConfigListener
>
configListenerRegistration
(){
return
new
ServletListenerRegistrationBean
<
ConfigListener
>(
new
ConfigListener
());
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment