Tag Archives: spring

解决Velocity+Spring的中文乱码问题

将spring配置中的velocity view改为: <bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"> <property name="resourceLoaderPath" value="/WEB-INF/vm/" /> <property name="velocityProperties"> <props> <prop key="input.encoding">utf-8</prop> <prop key="output.encoding">utf-8</prop>     </props>   </property> </bean> <bean id="velocityViewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver"> <property name="cache" value="true" /> <property name="suffix" value=".html" /> <property name="contentType" value="text/html;charset=UTF-8" /> </bean> <bean id=”velocityConfig” class=”org.springframework.web.servlet.view.velocity.VelocityConfigurer”> <property name=”resourceLoaderPath” value=”/WEB-INF/vm/” /> <property name=”velocityProperties”> <props> <prop key=”input.encoding”>utf-8</prop> <prop key=”output.encoding”>utf-8</prop> </props> </property> </bean> read more »

使用Spring LDAP ODM操作LDAP

Spring Source真的是个很神奇的开源社区,从《J2EE without EJB》开始为大家所知晓,到把IoC、AOP大范围地带到大家的开发模型中,再到和Hibernate、Struts组成每个Java函授学校必教的“SSH”组合,从此绿遍大江南北…… 在国内,大马路上随便抓一个Java程序员,10个里有9个半知道Spring;有9个知道怎么把SSH“组装”到一起(是的,“组装”,和流水线上的蓝领熟练工没有本质区别);有9个半知道IoC、AOP;有2个知道IoC和AOP的本质;有3个知道Spring其实分为core、context、orm、tx等不同子框架;有1个知道Spring 3之后可以用annotation取代之前版本大部分的xml配置;有2个知道Spring mvc和security;有半个知道其实Spring的子框架远不止这些……这就是我们当前Java码农们的实际情况。而造成这一局面的,我谓之三害——高校计算机系功利的培养模式、以北大青鸟为首的各种速成班的祸害和程序员们自己懒惰、人云亦云、拒绝思考的慢性自杀 牢骚发完,本文将通过介绍Spring的两个子框架:Spring LDAP和Spring LDAP ODM,来实现对LDAP的操作 项目主页:http://www.springsource.org/ldap,该框架通过提供和ORM中相似的机制对LDAP相关操作进行封装,主要包括: 类比SessionFactory的LdapContextSource 类比HibernateTemplate等的LdapTemplate 伪事务支持,能否与tx框架的TransactionManager混用未知 类比JPA的使用@Entry、@Attribute、@Id标注的ODM——Object Directory Mapping 本文(原先)目标:使用ODM将User类与LDAP中的实体进行映射,LDAP中的实体的objectClass包括inetOrgPerson,organizationalPerson,person,shadowAccount和top 相关配置文件、代码在http://static.springsource.org/spring-ldap/docs/1.3.x/reference/html/上已经很详细了,这里只是做一点旁注,全部来自于这几天和Spring LDAP的斗智斗勇 对于shadowAccount的shadowLastChange域,值是一个整形,至于具体含义网上没有找到解释,试了几次之后发现是从1970-1-1 00:00:00至今的天数,如果model里定义的是Date类型的话,需要自行实现org.springframework.ldap.odm.typeconversion.impl.Converter接口进行转换 对于@Entry标记,其中的objectClasses定义必须与objectClass完全一致。在新建和查询object时,ODM会根据此标记进行匹配,无需再指定objectClass 每个entry必须指定@Id字段,类型为javax.naming.Name,其实就是DN。但是若在LdapContextSource中指定了base,则DN将会按照base截取相对路径。比如,DN为cn=user,ou=users,dc=jayxu,dc=com,base为dc=jayxu,dc=com,则取出的user对象DN为cn=user,ou=users 如果使用Spring MVC对LDAP对象进行JSON序列化,必须注意javax.naming.Name中的某些字段无法被序列化,所以在转换成JSON之前需要将DN置null。一种方法是使用@JsonIgnoreProperties标记model类,比如:@JsonIgnoreProperties(“dn”) 对于不需要与LDAP进行映射的字段使用@Transient进行标记 考虑使用org.springframework.ldap.pool.factory.PoolingContextSource引入连接池 如果事务中需要与JDBC进行互操作,需要使用org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager作为tx manager

Spring之经验教训(一)

在现在的项目中我们使用了spring + hibernate + struts的架构,在享受aop, orm, ioc, di带来的种种便利的同时,我们亦遇到了很多莫名其妙或者说刻骨铭心的教训,今天先整理两点,日后继续补充 经验一:时刻牢记,spring、hibernate对对象 进行了动态代理,尽量不要试图在动态代理后的对象上进行反射,尤其是field! 不管是hibernate的orm还是spring的声明式事务管理,都对原来的pojo、dao进行了动态代理。虽然s、h“号称”动态代理做得天衣无缝且无色无味,但是,那只是在“绝大多数情况下”,如果想对动态代理后的对象进行反射,麻烦便来了,代码片段: public static void setCreditInfoStatus(CreditInfo info, CreditType type, CreditValidateStatus status) {     …       Field[] fields = CreditInfo.class.getDeclaredFields();       for (Field f : fields) {         if (f.isAnnotationPresent(Credit.class) && f.getAnnotation(Credit.class).value() == type) {         read more »

Spring之Hibernate+JBoss Treecache实现Hibernate集群

本文版权归本人所有,任何转载请标明出处 Hibernate作为一个ORM框架可以说已经做到了极致,但是绝大多数情况下Hibernate都被应用于单容器环境中,以至于互联网上能够找到的在集群环境中使用的参考少之又少,和Spring整合的就更别说了。实际上,Hibernate可以使用JBoss的Treecache作为二级缓存以支持分布式集群 本文将使用Spring 3.0.2框架集成Hibernate 3.5.2,并将Treecache 3.2.5作为二级缓存 Spring配置 <context:annotation-config />   <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">         … <property name="hibernateProperties">             <value>                 hibernate.dialect=org.hibernate.dialect.MySQL5Dialect                 hibernate.cache.use_second_level_cache=true                 hibernate.show_sql=true   read more »

Apache给EJB 3.1(JSR #318)投了否决票

刚才在Glassfish的Google Group上收到有关Apache在EJB 3.1 JSR表决上投了否决票的消息。过去看了一下,发现只有Apache投了否决票,Eclipse、Spring弃权,而且Apache的理由相当牛逼: On 2009-11-30 Apache Software Foundation voted No with the following comment: The Apache Software Foundation’s vote is based on the point of view that this spec lead – Sun – is in violation of the JSPA http://www.apache.org/jcp/sunopenletter.html and therefore shouldn’t be allowed to lead other JSRs until the above matter is read more »

无觅相关文章插件,快速提升流量