`
文章列表
注意,在Ubuntu下MySQL缺省是只允许本地访问的,如果你要其他机器也能够访问的话,那么需要改变/etc/mysql/my.cnf配置文件了!   默认的MySQL安装之后根用户是没有密码的,所以首先用根用户进入: $mysql -u root 在这里之所以用-u ...
Item 1 Consider static factory method instead of constructors   Advantages: One advantage of static factory methods is that, unlike constructors, they have names. (Mostly used in Java.utils.Collections) A second advantage of static factory methods is that, unlike constructors,they are not requ ...
昨天发现的问题今天又看了一下,Hibernate的SessionFactory接口的实现类是SessionFactoryImpl。它在创建Session时候的工作原理如下:     当调用SessionFactory.getCurrentSession的时候,它会调用CurrentSessionContext接口子类实例的currentSession()方法来获得Session,那CurrentSessionContext子类实例是怎么创建的呢? SpringFactoryImpl会根据配置文件制定的"hibernate.current_session_context_cl ...
在Service层上配置了切面加入了事务控制,但是在Dao层上没有配置事务。 用Spring-test编写了测试Dao的类,但是运行的时候报错: org.hibernate.HibernateException: No Session found for current thread at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:106) at org.hibernate.internal.SessionFactoryImpl.getC ...
使用Spring4.0+Hibernate4.3.0做项目,想用Unitils作为测试框架。由于项目采用Maven管理,所以在项目的POM文件下添加了Unitils的dependence。但是当我将应用部署到服务器上,出现了一个NoSuchMethod的错误:   java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/Session; at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter ...
1. vi/etc/init.d/tomcat7, Add below segment to the file, replace the ones marked in red by your tomcat installed path.   # Tomcat auto-start # # description: Auto-starts tomcat # processname: tomcat # pidfile: /var/run/tomcat.pid case $1 in start) sh /usr/share/tomcat7/bin/startup.sh ; ...
为Ubuntu server添加ufw防火墙,建议教程可以参照这里: http://wiki.ubuntu.org.cn/UFW防火墙简单设置 其实可以用man ufw来看一下ufw防火墙的设置选项。比较常用的步骤是:   1. 安装 sudo apt-get install ufw 2. 启用 sudo ufw enable 3.添加规则,设置允许访问的端口 sudo ufw allow 80 允许外部访问80端口 sudo ufw delete allow 80 禁止外部访问80 端口 sudo ufw allow from 192.168.1.1 允许 ...
以前搭环境总是现搜,现在记录一下,方便以后操作。 服务器是Ubuntu server 12.04 LTS 64bit 所有操作假设已经有root权限,若没有需要添加sudo。   一. 安装JDK 1.去Oracle官网下载jdk-6u45-linux-x64.bin,我是通过Windows下好了通过SSH传到服务器上。 2.在/usr/local里创建文件夹/installed/java,然后把下好的文件通传到该文件夹下。 3.cd /usr/local/installed/java,然后更改文件执行权限 chmod 777 jdk-6u45-linux-x64.bin 4 ...
公司开发遵循SCRUM,SCRUM倡导测试驱动开发,即Test-driven-development (TDD)。不可否认TDD是一个很好的东西,但是严格遵循TDD需要程序员付出更多的时间构造测试用例和维护测试用例,这势必是一种成本的增加,许多公司没有坚决执行TDD往往是由于项目的成本估算以及程序员的个人习惯。个人认为,长远来看使用TDD的开发方式可以起到磨刀不误砍柴工的作用,达到事半功倍的效果。   做Java开发最常用的自动化测试框架就是Junit,关于JUnit的资料有很多,这里就不一一列举了。简单的测试用例谁都会写,但是如果要构造拥有低权限访问控制修饰符修饰的属性并且没有提供ge ...
TimeMeasure是我以前写的一个java 辅助类,开发人员可以用它们在控制台打印任意两个步骤之间的时间消耗。中途可以pause这个时间计数方法,然后再resume回来,pause的时间是不计入到实际方法消耗的时间的。使用方法见TimeMeasure的main方法,另外如果你愿意,可以拓展它用log4j或者其他方式输出到文件。   TimeMeasure.java   public class TimeMeasure { // PTODO create junit test class private static HashMap<String, Tim ...
学习Spring的事务还要源于我在开发中遇到的困难。我的网站Server端是基于S2SH的。问题是这样的:   在Service层我有一个service,部分代码如下:     @Service("userService") @Transactional public class UserServiceImpl implements UserService { private static String getUserByNameHQL = "from User as user where user.userName = ?"; ...
一篇讲Spring声明式事务和编程式事务的文章 http://www.ibm.com/developerworks/cn/education/opensource/os-cn-spring-trans/section2.html   文章从概念上到分类再到实现,都进行了比较细致地讲解,对于想要了解Spring事务的同学是个不错的文章。   稍后会做一些总结

Spring配置filter

  filter和servlet不受spring管理,所以不能依赖注入spring管理的bean, 解决这个问题,一个方法是 在filter的init方法加入如下代码: //以private UserDao userDao;为例,注入依赖 WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(config.getServletContext()); userDao= (UserDao) wac.getBean("userDao");// ...

log4j配置问题

转一篇配置log4j的文章 http://blog.csdn.net/zhouqixiang/article/details/1958078
采用Servlet+jsp+javabean做web应用的时候,cookies没有设置path和maxAge,可以保存下来,可是在用Struts2的action存储cookies的时候却保存不下来,经过排查,需要添加如下两行代码: Cookie useridCook = new Cookie("userid", Integer.toString(user.getId())); useridCook.setPath("/"); //设置Path到应用根目录,否则保存不下来 useridCook.setMaxAge(DEFAULT_COOK ...
Global site tag (gtag.js) - Google Analytics