Seam 工程搭建记录(1)

1. SEAM 2.2 还是不能正常的支持JSF 2.0

尝试了2天还是搞不定, seam对jsf的phase解析就出现NullPointException, 换回jsf1.2问题就没有了, SEAM官方说可以无缝升级,但是事实上我搞不定

 

2. SEAM和Hibernate配合, 在注入session点时候, 变量名要和在componts.xml的如下配置的name属性一致

 

<persistence:managed-hibernate-session
		name="hibernateSession" session-factory="#{hibernateSessionFactory}"
		auto-create="true" session-factory-jndi-name="java:/AquariansSessionFactory" />

或者在注入的时候指定名字

@In(value="#{hibernateSession}")
protected Session session;

 

 

3. 试用泛型DAO时候,在初始化需要对从SEAM(org.jboss.seam.Instance)代理来的类进行处理

原来的代码

 

private Class<T> clazz;

	@SuppressWarnings("unchecked")
	public GenericDaoImpl() {
		
		this.clazz = (Class<T>) ((ParameterizedType) getClass()
				.getGenericSuperclass()).getActualTypeArguments()[0];
	}
 

 

需要进行进一步的判断

 

	private Class<T> clazz;

	@SuppressWarnings("unchecked")
	public GenericDaoImpl() {

		Type t = getClass().getGenericSuperclass();
		Type arg;
		
		/* 以下判断用于区分是否是代理类,如果是代理类需要再次获得一次GenericSuperclass */
		if (t instanceof ParameterizedType) {
			arg = ((ParameterizedType) t).getActualTypeArguments()[0];
		} else if (t instanceof Class) {
			arg = ((ParameterizedType) ((Class) t).getGenericSuperclass())
					.getActualTypeArguments()[0];

		} else {
			throw new RuntimeException("Can not handle type construction for '"
					+ getClass() + "'!");
		}

		if (arg instanceof Class) {
			this.clazz = (Class<T>) arg;
		} else if (arg instanceof ParameterizedType) {
			this.clazz = (Class<T>) ((ParameterizedType) arg).getRawType();
		} else {
			throw new RuntimeException("Problem dtermining generic class for '"
					+ getClass() + "'! ");
		}

	}

 

 

4. 注入泛型DAO时候需要添加创建属性,保证注入的对象为空的时候,让SEAM创建

 

@In(create = true)
private IUserDao userDao;

 

 

5.  SEAM和Hibernate结合的配置,

1. 配置好hibernate本身, 也就是hibernate.cfg.xml, 运行时能在classes目录下找到就可以了

2. 在components.xml文件中添加如下配置即可

 

<?xml version="1.0" encoding="UTF-8"?>
<components xmlns="http://jboss.com/products/seam/components"
	xmlns:core="http://jboss.com/products/seam/core" xmlns:persistence="http://jboss.com/products/seam/persistence"
	xmlns:security="http://jboss.com/products/seam/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:web="http://jboss.com/products/seam/web" xmlns:transaction="http://jboss.com/products/seam/transaction"
	xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.2.xsd 
                 http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.2.xsd 
                 http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.2.xsd
                 http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.2.xsd
                 http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.2.xsd
                 http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.2.xsd">


	

<persistence:hibernate-session-factory
		name="hibernateSessionFactory" />

	<persistence:managed-hibernate-session
		name="hibernateSession" session-factory="#{hibernateSessionFactory}"
		auto-create="true" session-factory-jndi-name="java:/AquariansSessionFactory" />

	<transaction:hibernate-transaction
		session="#{hibernateSession}" />

</components>

 

6. 如果要使用Tomcat作为开发调试使用,需要参照SEAM的Reference,在Tomcat上装上embedded jboss,然后修改相应配置文件, 这里要记录的时候, 如果在Eclipse上使用WTP工程,应该对应修改WTP添加的服务器的配置文件,而不是Tomcat本身

 

 7. 最后附带上maven的pom.xml文件到附件, 当作存档使用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值