您的位置:百味书屋 > 范文大全 > 经典范文 > spring,获取IP 正文

spring,获取IP

2016-10-25 00:12:02 来源网站:百味书屋

篇一:spring boot application properties配置详解

# SPRING CONFIG (ConfigFileApplicationListener) spring.config.name= # config file name (default to 'application')

spring.config.location= # location of config file # PROFILES spring.profiles.active= # comma list of active profiles

spring.profiles.include= # unconditionally activate the specified comma separated profiles # APPLICATION SETTINGS (SpringApplication) spring.main.sources= spring.main.web-environment= # detect by default spring.main.show-banner=true

spring.main....= # see class for all properties # LOGGING logging.path=/var/logs logging.file=myapp.log logging.config= # location of config file (default classpath:logback.xml for logback)

logging.level.*= # levels for loggers, e.g. "logging.level.org.springframework=DEBUG" (TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF) # IDENTITY (ContextIdApplicationContextInitializer) spring.application.name=

spring.application.index= # EMBEDDED SERVER CONFIGURATION (ServerProperties) server.port=8080 server.address= # bind to a specific NIC server.session-timeout= # session timeout in seconds

server.context-parameters.*= # Servlet context init parameters, e.g. server.context-parameters.a=alpha server.context-path= # the context path, defaults to '/' server.servlet-path= # the servlet path, defaults to '/' server.ssl.enabled=true # if SSL support is enabled server.ssl.client-auth= # want or need server.ssl.key-alias= server.ssl.ciphers= # supported SSL ciphers server.ssl.key-password= server.ssl.key-store= server.ssl.key-store-password= server.ssl.key-store-provider= server.ssl.key-store-type= server.ssl.protocol=TLS

server.ssl.trust-store=

server.ssl.trust-store-password= server.ssl.trust-store-provider= server.ssl.trust-store-type= server.tomcat.access-log-pattern= # log pattern of the access log server.tomcat.access-log-enabled=false # is access logging enabled server.tomcat.internal-proxies=10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|\\

192\\.168\\.\\d{1,3}\\.\\d{1,3}|\\

169\\.254\\.\\d{1,3}\\.\\d{1,3}|\\

127\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3} # regular expression matching trusted IP addresses server.tomcat.protocol-header=x-forwarded-proto # front end proxy forward header server.tomcat.port-header= # front end proxy port header server.tomcat.remote-ip-header=x-forwarded-for server.tomcat.basedir=/tmp # base dir (usually not needed, defaults to tmp) server.tomcat.background-processor-delay=30; # in seconds

server.tomcat.max-http-header-size= # maximum size in bytes of the HTTP message header server.tomcat.max-threads = 0 # number of threads in protocol handler

server.tomcat.uri-encoding = UTF-8 # character encoding to use for URL decoding # SPRING MVC (WebMvcProperties) spring.mvc.locale= # set fixed locale, e.g. en_UK spring.mvc.date-format= # set fixed date format, e.g. dd/MM/yyyy

spring.mvc.message-codes-resolver-format= # PREFIX_ERROR_CODE / POSTFIX_ERROR_CODE

spring.mvc.ignore-default-model-on-redirect=true # If the the content of the "default" model should be ignored redirects spring.view.prefix= # MVC view prefix spring.view.suffix= # ... and suffix spring.resources.cache-period= # cache timeouts in headers sent to browser

spring.resources.add-mappings=true # if default mappings should be added # SPRING HATEOS (HateoasProperties) spring.hateoas.apply-to-primary-object-mapper=true # if the primary mapper should also be configured # HTTP encoding (HttpEncodingProperties) spring.http.encoding.charset=UTF-8 # the encoding of HTTP requests/responses spring.http.encoding.enabled=true # enable http encoding support

spring.http.encoding.force=true # force the configured encoding # JACKSON (JacksonProperties)

spring.jackson.date-format= # Date format string (e.g. yyyy-MM-dd HH:mm:ss), or a fully-qualified date format class name (e.g.

com.fasterxml.jackson.databind.util.ISO8601DateFormat)

spring.jackson.property-naming-strategy= # One of the constants on Jackson's PropertyNamingStrategy (e.g. CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES) or the fully-qualified class name of a PropertyNamingStrategy subclass spring.jackson.deserialization.*= # see Jackson's DeserializationFeature spring.jackson.generator.*= # see Jackson's JsonGenerator.Feature spring.jackson.mapper.*= # see Jackson's MapperFeature spring.jackson.parser.*= # see Jackson's JsonParser.Feature

spring.jackson.serialization.*= # see Jackson's SerializationFeature # THYMELEAF (ThymeleafAutoConfiguration) spring.thymeleaf.check-template-location=true spring.thymeleaf.prefix=classpath:/templates/

spring.thymeleaf.excluded-view-names= # comma-separated list of view names that should be excluded from resolution

spring.thymeleaf.view-names= # comma-separated list of view names that can be resolved spring.thymeleaf.suffix=.html spring.thymeleaf.mode=HTML5 spring.thymeleaf.encoding=UTF-8 spring.thymeleaf.content-type=text/html # ;charset=<encoding> is added

spring.thymeleaf.cache=true # set to false for hot refresh # FREEMARKER (FreeMarkerAutoConfiguration) spring.freemarker.allow-request-override=false spring.freemarker.cache=true spring.freemarker.check-template-location=true spring.freemarker.charset=UTF-8 spring.freemarker.content-type=text/html spring.freemarker.expose-request-attributes=false spring.freemarker.expose-session-attributes=false spring.freemarker.expose-spring-macro-helpers=false spring.freemarker.prefix= spring.freemarker.request-context-attribute= spring.freemarker.settings.*= spring.freemarker.suffix=.ftl spring.freemarker.template-loader-path=classpath:/templates/ # comma-separated list spring.freemarker.view-names= # whitelist of view names that can be resolved # GROOVY TEMPLATES (GroovyTemplateAutoConfiguration) spring.groovy.template.cache=true spring.groovy.template.charset=UTF-8

spring.groovy.template.configuration.*= # See Groovy's TemplateConfiguration

spring.groovy.template.content-type=text/html spring.groovy.template.prefix=classpath:/templates/ spring.groovy.template.suffix=.tpl

spring.groovy.template.view-names= # whitelist of view names that can be resolved # VELOCITY TEMPLATES (VelocityAutoConfiguration) spring.velocity.allow-request-override=false spring.velocity.cache=true spring.velocity.check-template-location=true spring.velocity.charset=UTF-8 spring.velocity.content-type=text/html spring.velocity.date-tool-attribute= spring.velocity.expose-request-attributes=false spring.velocity.expose-session-attributes=false spring.velocity.expose-spring-macro-helpers=false spring.velocity.number-tool-attribute=

spring.velocity.prefer-file-system-access=true # prefer file system access for template loading spring.velocity.prefix= spring.velocity.properties.*= spring.velocity.request-context-attribute= spring.velocity.resource-loader-path=classpath:/templates/ spring.velocity.suffix=.vm

spring.velocity.toolbox-config-location= # velocity Toolbox config location, for example "/WEB-INF/toolbox.xml"

spring.velocity.view-names= # whitelist of view names that can be resolved # JERSEY (JerseyProperties) spring.jersey.type=servlet # servlet or filter spring.jersey.init= # init params

spring.jersey.filter.order= # INTERNATIONALIZATION (MessageSourceAutoConfiguration) spring.messages.basename=messages spring.messages.cache-seconds=-1

spring.messages.encoding=UTF-8

# SECURITY (SecurityProperties) security.user.name=user # login username security.user.password= # login password security.user.role=USER # role assigned to the user security.require-ssl=false # advanced settings ...

security.enable-csrf=false

security.basic.enabled=true security.basic.realm=Spring security.basic.path= # /** security.filter-order=0 security.headers.xss=false security.headers.cache=false security.headers.frame=false security.headers.content-type=false security.headers.hsts=all # none / domain / all security.sessions=stateless # always / never / if_required / stateless

security.ignored=false # DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties) spring.datasource.name= # name of the data source spring.datasource.initialize=true # populate using data.sql spring.datasource.schema= # a schema (DDL) script resource reference spring.datasource.data= # a data (DML) script resource reference spring.datasource.sql-script-encoding= # a charset for reading SQL scripts

spring.datasource.platform= # the platform to use in the schema resource (schema-${platform}.sql) spring.datasource.continue-on-error=false # continue even if can't be initialized spring.datasource.separator=; # statement separator in SQL initialization scripts spring.datasource.driver-class-name= # JDBC Settings... spring.datasource.url= spring.datasource.username= spring.datasource.password=

spring.datasource.jndi-name= # For JNDI lookup (class, url, username & password are ignored when set) spring.datasource.max-active=100 # Advanced configuration... spring.datasource.max-idle=8 spring.datasource.min-idle=8 spring.datasource.initial-size=10 spring.datasource.validation-query= spring.datasource.test-on-borrow=false spring.datasource.test-on-return=false spring.datasource.test-while-idle= spring.datasource.time-between-eviction-runs-millis= spring.datasource.min-evictable-idle-time-millis= spring.datasource.max-wait=

spring.datasource.jmx-enabled=false # Export JMX MBeans (if supported) # DATASOURCE (PersistenceExceptionTranslationAutoConfiguration

spring.dao.exceptiontranslation.enabled=true

篇二:java-SpringMVC

复习:

1)MVC模型

View:负责展示处理结果 JSP/HTML/FreeMarker/Velocity

Controller:负责接收请求、验证、调用ModelServlet/Filter/POJO

Model:负责业务功能(数据库、IO、Other) JavaBean

常见的MVC模型:SpringMVCStruts1 Sturts2ThinkPHP

2)SpringMVC

SpringMVC是一个带前端控制器的MVC模型,主要关注的是Controller(FrontController+RequestHandler),对View有部分涉及(提供了几个标签),并没有涉及到Model。

SpringMVC的处理流程:

(1)服务器一启动,SpringMVC创建BeanFactory,创建所有Bean对象

(2)客户端发起请求,被前端控制器拦截并解析

(3)Spring做URL-Handler映射,调用Hanlder

(4)Handler调用接收请求、验证、调用业务逻辑,返回viewName

(5)Spring查找ViewResolver,装配出一个可以请求转发的完整页面名

(6)View发送结果给客户端

3)使用SpringMVC的步骤:

(1)导入jar

(2)声明前端控制器 DispatcherServlet

(3)创建applicationContext-mvc.xml

(4)声明URL-Handler映射

(5)创建Handler、Service、Dao,声明为Spring中的Bean

(6)声明ViewResolver

(7)创建jsp

1.DispatcherServlet的url-pattern可取值有如下三种形式:

(1)<url-pattern>*.do</url-pattern> 只拦截以.do结尾的请求

(2)<url-pattern>/</url-pattern> 拦截所有的请求,包括Handler、js、css、jpg.....

注意:url-pattern不能指定为/*, 会导致handler能够被调用,但无法请求转发到jsp

2.使用注解实现URL-Handler的映射

(1)声明使用注解实现映射applicationContext.xml

<mvc:annotation-dirven />

(2)对Controller及其中的方法使用注解,进行URL映射

@RequestMapping(“/user”)

public class UserController{

@ReqeustMapping(“/add”)

public String add(){

return viewName;

} }

2.使用注解进行URL-Handler映射后,Hanlder获取请求参数的方式:

(1)Controller方法添加HttpServletRequest类型的形参即可,Spring调用此Controller方法时,会注入需要的request对象——不足:Controller依赖于一个Servlet容器对象,不便于进行独立的单元测试

public String add(HttpRequestServlet request){}

(2)Controller方法中声明与请求参数一样名称的形参即可——让Controller与Servlet容器解耦

public String add(String uname, String upwd, int uno){}

若请求参数的名称与Controller方法的形参名不一致,可以使用@RequestParam进行注解

public String add(@RequestParam(“userName”)String uname){}

(3)若Controller方法中需要注入的请求参数很多,可以封装为实体类,只要实体类的属性名与请求参数名一致,也可以实现注入:

public String add(Message msg, int uno){}

注意:有些情况下,如Controller方法向获取客户端所在IP地址,需要执行request.getRemoteIP(),request.getSession()只能使用方法一。

3.Controller中的数据传递给View的方式:

(1)通过HttpServletRequest.setAttribute

(2)让Controller的处理器方法返回ModelAndView对象,此对象中可以封装需要显示在页面

中的数据,Spring会从其中读取数据,调用request.setAttribute();保存在request范围

(3)为Controller处理方法添加一个ModelMap类型的形参,需要显示在View中的数据保存在此Map中即可。Spring会自动从此Map中读取数据添加到request范围。

4.SpringMVC应用中的中文乱码问题

(1)GET请求中数据的乱码:

GET/day109/add?uname=%AE%98HTTP/1.1

由于上述URI被tomcat截获,它默认理解为ISO8859-1字符集,可以修改它的配置文件server.xml

大约第70行 <Connector URIEncoding=”utf-8”....>

(2)POST请求中的乱码问题:

修改web.xml,声明一个字符集过滤器即可

<filter> <filter-name>characterEncodingFilter</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> </filter> <filter-mapping><filter-name>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>

5.让前端控制器对静态资源的请求进行放行

(1)方式一 DispatcherServlet的url-pattern作如下声明:

<url-pattern>*.do</url-pattern>

(2)方式二 若DispatcherServlet的url-pattern就特意声明为/,则可以在applicationContext中做过滤声明:

作业:

实现一个用户管理模块,包括如下功能:

前台(广大用户):

(1)注册新用户(用户名/密码/确认密码/邮箱/验证码/我同意)

(2)注册成功后,会提示成功,点击此处进行登录

(3)登录成功后,会提示欢迎回来:XXX,点击此处修改我的注册信息

(4)退出登录

后台(管理员功能):

(1)管理员登录

(2)登录成功后,浏览全部用户

(3)删除某个用户/一批用户

(4)(选作)锁定某个用户

篇三:Spring的依赖注入实现原理


spring,获取IP》出自:百味书屋
链接地址:http://www.850500.com/news/10054.html
转载请保留,谢谢!
查看更多相关内容>>spring,获取IP
相关文章
  • spring,获取IP

    springbootapplicationproperties配置详解 SPRINGCONFIG(ConfigFileApplicationListener)spring config name= configfilename(defaulttoapplication)spring config l

推荐范文