tomcat下的struts2+CDI(openwebbeans)+JPA配置
来源:互联网 发布:2017淘宝双12报名时间 编辑:程序博客网 时间:2024/06/05 20:39
上篇写了weld在tomcat中的集成后,发现apache openwebbeans也是可以整合的,自己太粗心,以前用tomEE的时候忘记了这个openwebbeans是其组成部分之一。本篇简单说一下openwebbeans作为CDI实现整合到tomcat中的方法。
其实大部分的整合方式都差不多,细节有变化而已。
依旧是Maven工程,增加依赖项:
<dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-atinject_1.0_spec</artifactId> <version>1.0</version></dependency><dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-jcdi_1.1_spec</artifactId> <version>1.0</version></dependency><dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-interceptor_1.2_spec</artifactId> <version>1.0</version> <scope>compile</scope></dependency><dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-annotation_1.2_spec</artifactId> <version>1.0</version> <scope>compile</scope></dependency><dependency> <groupId>org.apache.openwebbeans</groupId> <artifactId>openwebbeans-spi</artifactId> <version>${owb.version}</version> <scope>compile</scope></dependency><dependency> <groupId>org.apache.openwebbeans</groupId> <artifactId>openwebbeans-impl</artifactId> <version>${owb.version}</version> <scope>compile</scope></dependency> <dependency> <groupId>org.apache.openwebbeans</groupId> <artifactId>openwebbeans-web</artifactId> <version>${owb.version}</version> <scope>compile</scope></dependency>
<dependency> <groupId>org.apache.openwebbeans</groupId> <artifactId>openwebbeans-tomcat7</artifactId> <version>${owb.version}</version> <scope>compile</scope></dependency><dependency> <groupId>javax.validation</groupId> <artifactId>validation-api</artifactId> <version>1.1.0.Final</version></dependency>
web.xml中增加配置(包括openwebbeans监听器,BeanManager资源和数据源资源):
<listener> <listener-class>org.apache.webbeans.servlet.WebBeansConfigurationListener</listener-class> </listener><resource-env-ref> <description>Object factory for the CDI Bean Manager</description> <resource-env-ref-name>BeanManager</resource-env-ref-name> <resource-env-ref-type> javax.enterprise.inject.spi.BeanManager </resource-env-ref-type> </resource-env-ref> <resource-ref> <description>MySQL DBCP</description> <res-ref-name>jdbc/axon</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth></resource-ref>
在webroot/META-INF/context.xml中增加配置(BeanManager的JNDI和数据源):
<Resource name="BeanManager" auth="Container" type="javax.enterprise.inject.spi.BeanManager" factory="org.apache.webbeans.container.ManagerObjectFactory" /> <Resource name="jdbc/axon" auth="Container" type="javax.sql.DataSource" maxActive="20" maxIdel="10" maxWait="1000" username="root" password="kknd1234" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/axon?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8"> </Resource>
然后再按照上一篇中的配置,增加struts2的配置即可。JPA也不再重复了,和上一篇的相同。
这样就可以使用了,但是有一个问题我还没解决,就是增加了openwebbeans-tomcat7这个依赖以后,仍然不能按照官方说的可在servlet中进行注入。目前只能在strtus2中注入。有明白的请告诉我一下。(https://dzone.com/articles/using-apache-openwebbeans)
0 0
- tomcat下的struts2+CDI(openwebbeans)+JPA配置
- tomcat下的struts2+CDI(weld)+JPA配置
- CDI应用一 CDI与JPA整合
- JPA + Spring + struts2 配置
- spring jpa struts2配置
- Tomcat-----CDI编程实例
- 在WIN64 eclipse下配置Struts2+MySQL+Tomcat(一)
- 在WIN64 eclipse下配置Struts2+MySQL+Tomcat(二)
- 在WIN64 eclipse下配置Struts2+MySQL+Tomcat(三)
- 关于resin服务器下开发jpa+struts2.0+spring+hibernate+dwr的数据库表的ORM配置问题
- 在Tomcat7上配置JSF的CDI支持
- Tomcat下使用Spring + JPA 需要注意的问题
- Eclipse+Tomcat+Struts2的环境配置
- tomcat下配置struts2的Unable to load configuration.-bean-jar:file问题
- Struts2的基本配置(下)
- cdi
- win64下安装配置eclipse+struts2+mysql+tomcat
- 基于组件的编程CDI技术(概述)
- nrf51822 --- 外部中断(按键2)
- MVP设计模式思路
- mybatis查询,如果返回类型为resultType时,查询不到某些属性值问题
- 读取WEB-INF下的日志文件并添加到集合(windows和linux环境通用)
- android客服端+eps8266+单片机+路由器之远程控制系统
- tomcat下的struts2+CDI(openwebbeans)+JPA配置
- Uboot 常用指令
- ToolBar + DrawerLayout
- SQL批量删除表、数据
- 网络编程笔记
- Kali Rolling在虚拟机安装后的设置
- 一致性哈希算法应用与分析
- Makefile中的wildcard用法
- mysql中的日期转换函数(类似oracle中的to_date)