当前位置: 编程技术>综合
本页文章导读:
▪sonar 安装与配置(一) 首先 下载sonar :http://www.sonarsource.org/downloads/
我下载的version是:3.41版本
接下来 安装mysql ,这个就不多说了
创建一个名为sonar的库:
创建完库以后分配权限,创建一个sonar用户并把这个用户的.........
▪java中使用队列(java.util.Queue) 转自:http://blog.csdn.net/guijava/article/details/3784658
在java5中新增加了java.util.Queue接口,用以支持队列的常见操作。该接口扩展了java.util.Collection接口。
Queue使用时要尽量避免Collection的add()和remov.........
▪Servlet托管Spring进行管理 Servlet托管Spring时,
1、重写servlet中的init()方法,在servlet中使用WebApplicationContext 获取bean对象:
如下:
ArrivingShipsImpl asi;
public void init() throws ServletException {
super.init();
ServletCo.........
[1]sonar 安装与配置(一)
来源: 互联网 发布时间: 2013-11-10
首先 下载sonar :http://www.sonarsource.org/downloads/
我下载的version是:3.41版本
接下来 安装mysql ,这个就不多说了
创建一个名为sonar的库:
创建完库以后分配权限,创建一个sonar用户并把这个用户的密码设置为soanr 拥有这个库的所有权限:
打开你下载的sonar安装包 找到conf文件夹下的sonar.properties文件
保存关闭,打开bin/windows-x86-32(这个根据你的系统环境自行处理),点击StartSonar
稍等一会儿,第一次启动需要创建表和初始化相关数据
看到上面的画面,说明你启动成功了,打开浏览器输入:http://localhost:9000
到这里,恭喜你安装完毕!
对于像我这样的草根屌丝英文的界面用起来肯定不爽了,那好下载soanr的中文插件
地址:http://docs.codehaus.org/display/SONAR/Plugin+Library
在这里有丰富的插件,自己慢慢看吧,以后有时间一一讲解它们的用途
插件也可以从系统本身的插件库进行安装,在系统配置里可以进行安装
将down下来的中文包放到*/sonar-3.4.1\extensions\plugins下边,如上图所示,然后重新启动即可
作者:frank0417 发表于2013-1-12 17:51:05 原文链接
阅读:20 评论:0 查看评论
[2]java中使用队列(java.util.Queue)
来源: 互联网 发布时间: 2013-11-10
转自:http://blog.csdn.net/guijava/article/details/3784658
在java5中新增加了java.util.Queue接口,用以支持队列的常见操作。该接口扩展了java.util.Collection接口。
Queue使用时要尽量避免Collection的add()和remove()方法,而是要使用offer()来加入元素,使用poll()来获取并移出元素。它们的优点是通过返回值可以判断成功与否,add()和remove()方法在失败的时候会抛出异常。 如果要使用前端而不移出该元素,使用
element()或者peek()方法。
值得注意的是LinkedList类实现了Queue接口,因此我们可以把LinkedList当成Queue来用。
[java] view
plaincopy
[3]Servlet托管Spring进行管理
Servlet托管Spring时,
1、重写servlet中的init()方法,在servlet中使用WebApplicationContext 获取bean对象:
如下:
2、实现ApplicationContextAware接口的SpringConetextUtil类,利用回调方法,设置上下文对象,通过上下文对象获取bean对象
3、动态代理形式的:
http://blog.csdn.net/yaerfeng/article/details/7368541
思路:把servlet配置为spring的bean,就可以实现其他bean的注入,然后使用代理servlet来辅助配置和运行:
一、代理servlet的写法:
二、业务servlet的写法:
三、业务serlvet配置为spring的bean:
四、web.xml中业务servlet的配置:
已有 0 人发表留言,猛击->>这里<<-参与讨论
ITeye推荐
1、重写servlet中的init()方法,在servlet中使用WebApplicationContext 获取bean对象:
如下:
ArrivingShipsImpl asi;
public void init() throws ServletException {
super.init();
ServletContext servletContext = this.getServletContext();
WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
asi = (ArrivingShipsImpl)ctx.getBean("arrivingShipsImpl");
}
2、实现ApplicationContextAware接口的SpringConetextUtil类,利用回调方法,设置上下文对象,通过上下文对象获取bean对象
@Component
public class SpringContextUtil implements ApplicationContextAware{
private static ApplicationContext applicationContext;
/**
* 实现ApplicationContextAware接口的回调方法,设置上下文环境
*/
public void setApplicationContext(ApplicationContext applicationContext){
SpringContextUtil.applicationContext = applicationContext;
}
public static ApplicationContext getApplicationContext(){
return applicationContext;
}
/**
* 获取对象
*/
public static Object getBean(String name) throws BeansException{
return applicationContext.getBean(name);
}
}
3、动态代理形式的:
http://blog.csdn.net/yaerfeng/article/details/7368541
思路:把servlet配置为spring的bean,就可以实现其他bean的注入,然后使用代理servlet来辅助配置和运行:
一、代理servlet的写法:
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
/**
* HttpServlet 代理
* @author lwei
* @since 2011-03-17
* @version 1.0
*/
public class HttpServletProxy extends HttpServlet {
/**
* random serialVersionUID
*/
private static final long serialVersionUID = -7208519469035631940L;
Log logger = LogFactory.getLog(HttpServletProxy.class);
private String targetServlet;
private HttpServlet proxy;
public void init() throws ServletException {
this.targetServlet = getInitParameter("targetServlet");
getServletBean();
proxy.init(getServletConfig());
logger.info(targetServlet + " was inited by HttpServletProxy successfully......");
}
private void getServletBean() {
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
this.proxy = (HttpServlet) wac.getBean(targetServlet);
}
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, RuntimeException {
proxy.service(request, response);
}
}
二、业务servlet的写法:
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author lwei
*/
public class UserCheckServlet extends HttpServlet {
/**
* random serialVersionUID
*/
private static final long serialVersionUID = 3075635113536622929L;
private UserService userService;(UserService 是spring托管的bean,通过set方法注入)
public void setUserService (UserService userService) {
this.userService = userService;
}
public UserCheckServlet() {
super();
}
public void init() throws ServletException {
super.init();
}
@Override
public void service(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
throws ServletException, IOException, RuntimeException {
....
....
userService.getUserByCode();(注入后bean的使用)
....
....
}
}
三、业务serlvet配置为spring的bean:
<bean id="userCheckServlet" />
四、web.xml中业务servlet的配置:
<servlet>
<servlet-name>UserCheckProxy</servlet-name>
<servlet-class>com.XXX.xxxx.web.HttpServletProxy</servlet-class>
<init-param>
<param-name>targetServlet</param-name>
<param-value>userCheckServlet</param-value>(业务servlet配置为spring的bean时的名字)
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>UserCheckProxy</servlet-name>
<url-pattern>/UserCheck</url-pattern>
</servlet-mapping>
已有 0 人发表留言,猛击->>这里<<-参与讨论
ITeye推荐
- —软件人才免语言低担保 赴美带薪读研!—
最新技术文章:
 
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!