跳至主要内容

博文

目前显示的是 三月, 2016的博文

Annotations in JBoss Deployment

在我们书写EJB代码时,为了简化配置,我们使用了注解而不是xml配置文件。那么,JBoss(或者说Wildfly)是如何利用这些注解,在合适的时候调用了我们的代码呢?换句话说,jboss从启动到输出像这样的jndi设置信息的部署过程究竟发生了什么?今天我们就通过分析其源代码简单探讨一下这个问题。 从annotations讲起 在开发过程中, 我们也时常会在应用代码中会看到这些看上去比较奇怪的@开头的东西,例如@Override, @Deprecated。他们的作用到底是什么?又是如何实现的呢?我们稍稍介绍以一跟我们今天内容相关的背景。 注解,根据其寿命长短,可以分为三类: Source:只存在于源代码中,在编译后便被丢弃。所以说他的作用范围便是编译时。 Class:在class文件中,但不在VM中。貌似没有什么卵用 Runtime:一直存活到VM中,即可以通过反射获得注释信息(用大白话说就是,当你程序跑起来之后,还可以获取注解的内容)。 所以,联想到我们在使用EJB的过程:先写好源代码,再编译,再打包,再交给jboss部署,jboss再调用我们的代码。我们可以明白,诸如@Stateless, @EJB这样的注解都是第三类注解。 JBoss部署 在上面讲的使用EJB的过程中,jboss的部署其实还是一个黑盒,所以当我们把我们的jar包部署到JBoss时究竟发生了什么? 让我们通过源代码(org/jboss/as/server/deployment/Phase.java)把部署过程理一理: /** * This phase creates the initial root structure. Depending on the * service for this phase will ensure that the * deployment unit's initial root structure is available and accessible. * Upon entry, this phase performs the following actions: * <ul> * <li>The primary deployment root is mounted

Learn struts2 and JPA: by trial and error

This blog shares some errors we met, and some problem we encountered, to assist future reader. org.hibernate.LazyInitializationException Detailed error message is following: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: entity.Branch.plans, could not initialize proxy - no Session Here is a strange solution for lazy fetch and finally I give bidirectional relationship and this problem solved. @OneToOne with Shared Primary Key Code sample: public class User { @Id Integer id; @OneToOne (mappedBy = "user" ) @PrimaryKeyJoinColumn Account account; } public class Account { @Id Integer id; @MapsId @OneToOne @JoinColumn (name = "uid" ) User user; public Account (User user) { this .user = user; /* id = user.getUid(); can't assign it, why? error: null value was assigned to a property of primitive type setter uid