Arganzheng's Blog

stay hungry, stay foolish

如何在远程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: ...

创建可执行的jar包

今天打算将Swing桌面程序打包成一个可以执行的jar包发布,方便用户使用。 可执行的jar包其实原理很简单,就是在jar包的manifest文件中用Main-Class标明你的应用程序入口: Main-Class: classname。其中classname是类的全路径名,不包含.class后缀,跟Spring的配置一样。 然后你就可以直接鼠标双击该jar包,或者在命令行中执行如下命令启动该jar了: java -jar JAR-name 在ant脚本中这通过一个简单的脚本就可以完成了: <project name="me.arganzheng.study.util" basedir="." default="usage"> ...

JUnit与Spring的整合——JUnit的TestCase如何自动注入Spring容器托管的对象

问题 在Java中,一般使用JUnit作为单元测试框架,测试的对象一般是Service和DAO,也可能是RemoteService和Controller。所有这些测试对象基本都是Spring托管的,不会直接new出来。而每个TestCase类却是由JUnit创建的。如何在每个TestCase实例中注入这些依赖呢? 预期效果 我们希望能够达到这样的效果: package me.arganzheng.study; import static org.junit.Assert.*; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; /** ...

×