Arganzheng's Blog

stay hungry, stay foolish

负载均衡

高性能高可用性的系统一般会有多层次的负载均衡(High-performance systems may use multiple layers of load balancing)。负责均衡的实现机制有硬件和软件两种。下面我们以top down的方式一层层介绍下去。 总体来说负责均衡分为无状态服务负载均衡,以及有状态的数据负载均衡两类。前者(比如web server,app Server)由于是无状态的,所以backen-server是对等的,可以路由到任何一台机器,路由的策略一般是业务无关的(灰度除外),比如backen-server的负载情况。而对于有状态的数据负载均衡(比如cache,MQ或者DB),对等是基本不可能的,因为数据存放多份带来的写压力以及一致性...

如何使用tomcat高效调试

1. 使用maven tomcat插件快速部署和启动web工程: mvn tomcat:run 如果要调试,可以先在命令行设置如下环境变量: Windows: set MAVEN_OPTS=-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 Linux: export MAVEN_OPTS=-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 然后在eclipse中就可以链接8000端口(可随意设定)进行调试了。 TIPS 如果是tomcat7的话,需要制定版本号:mvn tomcat7:run。 2. 使用E...

如何在远程Linux机器上执行Shell命令

通常我们需要写个shell脚本然后放上服务器上执行。一般的步骤是先登陆上服务器,然后将shell脚本上传到服务器的某个目录下,最后是执行这个脚本。然而shell本身是支持远程执行的。 可以使用如下命令: ssh user@server bash < /path/to/local/script.sh 在远程机器上运行一段脚本。这条命令最大的好处就是不用把脚本拷到远程机器上。 如果你只是想执行on line command,那么可以使用管道: echo "date" | ssh user@server bash 当然,远程执行的前提其实是要先ssh到服务器的,需要身份验证。可以使用except或者ssh public key来实现免密码登陆。这样就...

域名解析过程及其相关配置

/etc/host.conf The host.conf File The central file that controls your resolver setup is host.conf. It resides in /etc and tells the resolver which services to use, and in what order. Options in host.conf must occur on separate lines. Fields may be separated by white space (spaces or tabs). A hash sign (#) introduces a comment tha...

使用Spring-Security进行登录控制的session问题

这边文章Spring Security Form Login Using Database对Spring Security做了非常简单明了的介绍。而且有一个可以down下来运行的示例工程。笔者试验了一下,发现一些有意思的问题。 访问http://localhost/SpringMVC/login,填写用户名和密码,点击登录按钮,发生如下请求: Request URL:http://localhost/SpringMVC/j_spring_security_check Request Method:POST Status Code:302 Moved Temporarily Request Headers Accept:text/html,applicatio...

Restful Spring MVC

Spring MVC本身对Restful支持非常好。它的@RequestMapping、@RequestParam、@PathVariable、@ResponseBody注解很好的支持了REST。18.2 Creating RESTful services 1. @RequestMapping Spring uses the @RequestMapping method annotation to define the URI Template for the request. 类似于struts的action-mapping。 可以指定POST或者GET。 2. @PathVariable The @PathVariable method paramete...

Spring的Bean Scopes

Spring一共支持5种bean scopes,其中3种需要web-aware ApplicationContext。Bean Scopes out of the box, the Spring Framework supports exactly five scopes (of which three are available only if you are using a web-aware ApplicationContext). singleton Scopes a single bean definition to a single object instance per Spring IoC container. ...

Spring的Bean Scopes实现机制源码剖析

关于Spring的bean scopes,在我的上一篇文章 Spring的Bean Scopes 已经做了详细的介绍,这里我们探讨一下Spring的bean scopes底层是怎么实现的。 通过下面这行简单的配置: <bean class="me.arganzheng.study.scope.FooUser" scope="request"> <aop:scoped-proxy /> </bean> 为什么我们就可以让FooUser每次请求都生成新实例,而且可以注入到生命周期比它长的singleton bean中呢? public class FooService{ @Autowired FooUse...

JUnit与Spring的整合——JUnit中的TestCase如何拥有spring的事务管理机制

问题 很多时候我们不希望单元测试的结果玷污了数据库,玷污了我们也不希望人肉去check,我们希望它无痕迹的悄悄执行,告诉我最终结果即可。那么怎样让你的UT也具有事务功能呢? 预期效果 我们希望能够达到这样的效果: package me.arganzheng.study; import static org.junit.Assert.*; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.Rollback; /** * * @author ar...

Spring与web MVC的整合——Spring的应用上下文管理

问题1 如何让web容器加载你的web MVC框架 对于基于servlet的web容器来说,遵循的是servlet规范,入口配置文件是web.xml。这类web容器会在启动的时候会而且仅会加载如下三种类型的对象: servlet context listener filter 而且有一定的加载和销毁顺序! Loading Servlets, Context Listeners, and Filters Servlets, Context Listeners, and Filters are loaded and destroyed in the following order: Order of loading: ...

×