当前位置: 首页 > 工具软件 > Seam Security > 使用案例 >

Seam2.1.x学习笔记(二)

解晟
2023-12-01
  • JBoss Seam 2.1.1.GA + Tomcat 6.0.18实战指南

一、 准备软件:

      JBoss Seam 2.1.1.GA

      JBoss 4.2.2.GA

      Tomcat 6.0.18

      JBoss Tools 3.0.0.CR2

      Eclipse 3.4.1

      首先安装好Eclipse + JBoss Tools作为开发环境,具体方法就不多说了。

 

二、新建Seam工程

      在Eclipse中选择新建项目-> Seam Project,操作步骤按照流程继续,需要注意的是:

      1. 选择seam 2.1类型;

      2. 工程采用war格式;

      为方便描述,工程名称就叫helloseam

三、在tomcat上运行helloseam

      在tomcat上运行helloseam,会报很多错误,错误类型如下:

      1. Class Not Found错误,找不到jar包;

      2. 数据源找不到,这是因为helloseam的persistent.xml中引用的数据源需要在tomcat的conf/context.xml进行单独配置;

      3. 一些配置信息需要更新;

      下面继续解决运行中的错误。

四、解决jar包的依赖关系

      需要添加到WEB-INF/lib下的jar包清单如下:

  2009-01-05  09:51            92,015 antlr-runtime.jar
  2009-01-05  09:51           188,671 commons-beanutils.jar
  2009-01-05  11:20           571,259 commons-collections.jar
  2009-01-05  09:51           143,602 commons-digester.jar
  2009-01-05  11:20           305,001 commons-httpclient.jar
  2009-01-05  11:20            83,613 commons-io.jar
  2009-01-05  11:20           245,274 commons-lang.jar
  2009-01-05  10:35            55,424 commons-logging.jar
  2009-01-05  11:20           170,389 concurrent.jar
  2009-01-05  09:51         4,014,911 core.jar
  2009-01-05  10:25           313,128 dom4j.jar
  2009-01-05  09:51           559,696 drools-compiler.jar
  2009-01-05  09:51         1,074,902 drools-core.jar
  2009-01-05  10:28            52,220 ejb3-persistence.jar
  2009-01-05  10:34           265,130 hibernate-annotations.jar
  2009-01-05  10:34            66,426 hibernate-commons-annotations.jar
  2009-01-05  10:34           116,544 hibernate-entitymanager.jar
  2009-01-05  10:34           198,363 hibernate-search.jar
  2009-01-05  10:34            60,992 hibernate-validator.jar
  2009-01-05  10:34         2,242,529 hibernate.jar
  2009-01-05  10:23           547,559 javassist.jar
  2009-01-05  10:35           406,564 jboss-common.jar
  2009-01-05  09:51           134,342 jboss-el.jar
  2009-01-05  10:26           423,706 jboss-j2ee.jar
  2009-01-05  09:51            15,240 jboss-seam-debug.jar
  2009-01-05  09:51           118,141 jboss-seam-excel.jar
  2009-01-05  09:51            47,897 jboss-seam-ioc.jar
  2009-01-05  09:51            28,246 jboss-seam-mail.jar
  2009-01-05  09:51            82,557 jboss-seam-pdf.jar
  2009-01-05  09:51           101,388 jboss-seam-remoting.jar
  2009-01-05  09:51           264,476 jboss-seam-ui.jar
  2009-01-05  09:51         1,109,128 jboss-seam.jar
  2009-01-05  09:51           668,249 jbpm-jpdl.jar
  2009-01-05  10:33           341,141 jsf-api.jar
  2009-01-05  09:51           302,352 jsf-facelets.jar
  2009-01-05  11:21           826,780 jsf-impl.jar
  2009-01-05  09:51           772,495 jxl.jar
  2009-01-05  11:19           664,675 lucene-core.jar
  2009-01-05  09:51         1,117,312 mvel14.jar
  2009-01-05  09:51           168,457 richfaces-api.jar
  2009-01-05  09:51         1,494,536 richfaces-impl.jar
  2009-01-05  09:51         2,525,758 richfaces-ui.jar
                42 个文件     22,981,088 字节
                 0 个目录 12,236,599,296 可用字节
   以上jar包均来自JBoss Seam 2.1.1.GA和JBoss 4.2.2.GA的内容。

 

五、添加tomcat的数据源:

注意,需要在Eclipse的Package Explore->Servers/Tomcat v6.0 Server at localhost-config/context.xml中修改,内容如下:

<?xml version='1.0' encoding='gbk'?>
	<!--
		Licensed to the Apache Software Foundation (ASF) under one or more
		contributor license agreements. See the NOTICE file distributed with
		this work for additional information regarding copyright ownership.
		The ASF licenses this file to You under the Apache License, Version
		2.0 (the "License"); you may not use this file except in compliance
		with the License. You may obtain a copy of the License at

		http://www.apache.org/licenses/LICENSE-2.0 Unless required by
		applicable law or agreed to in writing, software distributed under the
		License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
		CONDITIONS OF ANY KIND, either express or implied. See the License for
		the specific language governing permissions and limitations under the
		License.
	-->
	<!--
		The contents of this file will be loaded for each web application
	-->
<Context docBase="helloseam" path="seamtomcat">

	<!-- Default set of monitored resources -->
	<WatchedResource>WEB-INF/web.xml</WatchedResource>

	<!--
		Uncomment this to disable session persistence across Tomcat restarts
	-->
	<!--  以下设置是用于避免Tomcat启动时的Exception loading sessions from persistent storage错误的,http://pingfang.iteye.com/blog/126600  -->
                <Manager className="org.apache.catalina.session.PersistentManager" saveOnRestart="false"/> 

	<!--
		Uncomment this to enable Comet connection tacking (provides events on
		session expiration as well as webapp lifecycle)
	-->
	<!--
		<Valve
		className="org.apache.catalina.valves.CometConnectionManagerValve" />
	-->
	<Resource name="jdbc/helloseamDatasource" auth="Container"
		type="javax.sql.DataSource" maxActive="10" maxIdle="5" maxWait="10000"
		username="informix" password="passwd" driverClassName="com.informix.jdbc.IfxDriver"

		url="jdbc:informix-sqli://0.0.0.0:9001/mydb:INFORMIXSERVER=myserver;DELIMIDENT=y;" />

	<ResourceLink global="jdbc/helloseamDatasource" name="jdbc/helloseamDatasource"
		type="javax.sql.DataSource" />
</Context>

  

  以上配置使用informix数据库,需要将ifxjdbc.jar放在tomcat的lib目录下。

 

六、修改helloseam/src/main/persistent.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- Persistence deployment descriptor for dev profile -->
<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
             version="1.0">
             
   <persistence-unit name="helloseam" transaction-type="RESOURCE_LOCAL">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:comp/env/jdbc/helloseamDatasource</jta-data-source>
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.InformixDialect"/>
         <property name="hibernate.hbm2ddl.auto" value="update"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.format_sql" value="true"/>
         <!-- for JBoss, not for tomcat,需要被注释掉
			<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
		 -->
      </properties>
   </persistence-unit>
    
</persistence>

 

 七、修改helloseam/webContent/WEB-INF/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:drools="http://jboss.com/products/seam/drools"
            xmlns:bpm="http://jboss.com/products/seam/bpm"
            xmlns:security="http://jboss.com/products/seam/security"
            xmlns:mail="http://jboss.com/products/seam/mail"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:transaction="http://jboss.com/products/seam/transaction"
            xsi:schemaLocation=
                "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
                 http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd
                 http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd
                 http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd
                 http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                 http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd
                 http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd
                 http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.1.xsd">

   <core:init debug="true" jndi-pattern="@jndiPattern@"/>

   <component name="org.jboss.seam.debug.hotDeployFilter">
      <property name="urlPattern">*.seam</property>
   </component>
 
   <core:manager concurrent-request-timeout="500"
                 conversation-timeout="120000"
                 conversation-id-parameter="cid"
                 parent-conversation-id-parameter="pid"/>

   <persistence:managed-persistence-context name="entityManager"
                                     auto-create="true"
                          entity-manager-factory="#{helloseamEntityManagerFactory}"/>

   <persistence:entity-manager-factory name="helloseamEntityManagerFactory"
                      persistence-unit-name="helloseam"/>

   <drools:rule-base name="securityRules">
      <drools:rule-files><value>/security.drl</value></drools:rule-files>
   </drools:rule-base>

   <security:rule-based-permission-resolver security-rules="#{securityRules}"/>

   <security:identity authenticate-method="#{authenticator.authenticate}" remember-me="true"/>

   <event type="org.jboss.seam.security.notLoggedIn">
      <action execute="#{redirect.captureCurrentView}"/>
   </event>
   <event type="org.jboss.seam.security.loginSuccessful">
      <action execute="#{redirect.returnToCapturedView}"/>
   </event>

   <mail:mail-session host="localhost" port="2525" username="test" password="test" />

   <!-- For use with jBPM pageflow or process management -->
   <!--
   <bpm:jbpm>
      <bpm:process-definitions></bpm:process-definitions>
      <bpm:pageflow-definitions></bpm:pageflow-definitions>
   </bpm:jbpm>
   -->
   <transaction:entity-transaction entity-manager="#{entityManager}"/>

</components>

 

 八、正常启动helloseam

    现在可以正常启动helloseam应用,打开http://localhost:8080/helloseam可以看到首页面,点击其他页面也不会发生错误。

 

九、创建Seam组件

   现在默认的程序可以正常启动了,我们准备使用 Seam Generate Entities 工具从数据库中逆向生成默认的Seam组件吧。

   假设使用user_basic表,生成代码后重新部署helloseam,可以发现程序报错了,提示有一些类找不到,不用怕,在WEB-INF/lib下添加:cglib-nodep.jar  antlr.jar即可。

   现在可以正常启动了,访问:http://localhost:8080/helloseam/UserBasicList.seam可以打开页面并进行添加删除操作。

  现在一个带基本的CRUD功能的Seam应用诞生了,可以跑在Tomcat下,对于开发环境来说的确省事不少,至少启动速度比JBoss快多了,哈哈哈。

  欢迎你的Seam之旅,快快来吧。

 

十、参考资料:

   tomcat 6.0连接池配置

  在tomcat下做SEAM开发的详解

 

 

 

 

 

 

 

 

 

 

 类似资料: