2016-08-31 81 views
1

我認爲用CDI bean替換JSF bean會很容易。但這是一個緩慢的開始。非常慢。如何在Tomcat 8.5上使用CDI和JSF

我使用的是Tomcat 8.5和JSF 2.2,我試圖使用CDI。我嘗試了不同的配置,不同的結果但沒有任何效果,所以我遵循http://balusc.omnifaces.org/2013/10/how-to-install-cdi-in-tomcat.html中的方向,這就是我所得到的結果。

SEVERE: A child container failed during start 
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/Workflow]] 
at java.util.concurrent.FutureTask.report(FutureTask.java:122) 
at java.util.concurrent.FutureTask.get(FutureTask.java:192) 
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:911) 
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:890) 
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152) 
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1403) 
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1393) 
at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
at java.lang.Thread.run(Thread.java:745) 

我的配置是:

\ META-INF \ context.xml的

<!-- language: lang-html --> 
<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<Context reloadable="true"> 
<Resources   cachingAllowed="true" cacheMaxSize="20000"  /> 

<Resource 
name="jdbc/FlowDB" 
auth="Container" 
type="javax.sql.DataSource" 
maxActive="100" 
maxIdle="30" 
maxWait="10000" 
username="xxxx" 
password="xxxxxxxxxxx" 
driverClassName="com.mysql.jdbc.Driver" 
url="jdbc:mysql://localhost:3306/flow?autoReconnect=true" /> 

<Resource 
name="mail/Session" 
auth="Container" 
type="javax.mail.Session" 
mail.smtp.host="localhost" 
mail.smtp.port="25" 
mail.smtp.auth="true" 
mail.smtp.user="[email protected]" 
mail.smtp.password="123456" /> 

<!-- Binding BeanManager to JNDI --> 
<Resource 
name="BeanManager" 
auth="Container" 
type="javax.enterprise.inject.spi.BeanManager" 
factory="org.jboss.weld.resources.ManagerObjectFactory"/> 

<!--        --> 

</Context> 

\ WEB-INF \ beans.xml中

<?xml version="1.0" encoding="UTF-8"?> 
<beans 
xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" 
bean-discovery-mode="annotated" 
> 
</beans> 

Pom.xml

<build> 
<plugins> 
<plugin> 
<groupId>org.apache.maven.plugins</groupId> 
<artifactId>maven-compiler-plugin</artifactId> 
<version>3.1</version> 
<configuration> 
<source>1.8</source> 
<target>1.8</target> 
</configuration> 
</plugin> 

<plugin> 
<artifactId>maven-resources-plugin</artifactId> 
<version>2.7</version> 
<configuration> 
<encoding>UTF-8</encoding> 
</configuration> 
</plugin> 

<plugin> 
<groupId>org.apache.maven.plugins</groupId> 
<artifactId>maven-war-plugin</artifactId> 
<version>2.6</version> 
</plugin> 
</plugins> 
</build> 

<dependencies> 
<dependency> 
<groupId>org.glassfish</groupId> 
<artifactId>javax.faces</artifactId> 
<version>2.2.10</version> 
</dependency> 

<!-- Hibernate --> 
<dependency> 
<groupId>org.hibernate</groupId> 
<artifactId>hibernate-core</artifactId> 
<version>4.3.4.Final</version> 
</dependency> 

<dependency> 
<groupId>org.jboss.logging</groupId> 
<artifactId>jboss-logging</artifactId> 
<version>3.3.0.Final</version> 
</dependency> 
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator --> 
<dependency> 
<groupId>org.hibernate</groupId> 
<artifactId>hibernate-validator</artifactId> 
<!--   <version>4.3.2.Final</version> --> 
<version>5.2.4.Final</version> 
</dependency> 
<!-- MySQL --> 
<dependency> 
<groupId>mysql</groupId> 
<artifactId>mysql-connector-java</artifactId> 
<version>5.1.30</version> 
<scope>provided</scope> 
</dependency> 

<!-- Spring --> 
<dependency> 
<groupId>org.springframework.security</groupId> 
<artifactId>spring-security-web</artifactId> 
<version>${spring.security.version}</version> 
</dependency> 
<dependency> 
<groupId>org.springframework.security</groupId> 
<artifactId>spring-security-config</artifactId> 
<version>${spring.security.version}</version> 
</dependency> 
<dependency> 
<groupId>org.springframework</groupId> 
<artifactId>spring-jdbc</artifactId> 
<version>${spring.version}</version> 
</dependency> 

<!-- SPRING DATA JPA - https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa --> 
<dependency> 
<groupId>org.springframework.data</groupId> 
<artifactId>spring-data-jpa</artifactId> 
<version>1.10.2.RELEASE</version> 
</dependency> 

<dependency> 
<groupId>commons-logging</groupId> 
<artifactId>commons-logging</artifactId> 
<version>1.1.1</version> 
</dependency> 

<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 --> 
<dependency> 
<groupId>org.apache.commons</groupId> 
<artifactId>commons-lang3</artifactId> 
<version>3.4</version> 
</dependency> 

<!-- https://mvnrepository.com/artifact/javax.enterprise/cdi-api 'INFO: CDI @ViewScoped bean functionality unavailable' http://weld.cdi-spec.org/ 
--> 

<dependency> 
<groupId>org.jboss.weld.servlet</groupId> 
<artifactId>weld-servlet</artifactId> 
<version>2.3.5.Final</version> 
</dependency> 

<!-- Primefaces --> 
<dependency> 
<groupId>org.primefaces</groupId> 
<artifactId>primefaces</artifactId> 
<version>5.3</version> 
</dependency> 

<!-- Primefaces Theme --> 
<!-- https://mvnrepository.com/artifact/org.primefaces.extensions/all-themes --> 
<dependency> 
<groupId>org.primefaces.themes</groupId> 
<!-- <artifactId>all-themes</artifactId> --> 
<artifactId>bootstrap</artifactId> 
<version>1.0.8</version> 
</dependency> 

<!-- Email --> 
<dependency> 
<groupId>javax.mail</groupId> 
<artifactId>mail</artifactId> 
<version>1.4.5</version> 
<scope>provided</scope> 
</dependency> 
<dependency> 
<groupId>org.apache.commons</groupId> 
<artifactId>commons-email</artifactId> 
<version>1.3.3</version> 
</dependency> 


<!-- JUnit » 4.12 --> 
<!-- https://mvnrepository.com/artifact/junit/junit --> 
<dependency> 
<groupId>junit</groupId> 
<artifactId>junit</artifactId> 
<version>4.12</version> 
</dependency> 

<!-- slf4j-log4j --> 

<dependency> 
<groupId>org.apache.logging.log4j</groupId> 
<artifactId>log4j-api</artifactId> 
<version>2.6.2</version> 
</dependency> 

<dependency> 
<groupId>org.apache.logging.log4j</groupId> 
<artifactId>log4j-core</artifactId> 
<version>2.6.2</version> 
</dependency> 

<!-- https://mvnrepository.com/artifact/org.webjars/font-awesome --> 
<dependency> 
<groupId>org.webjars</groupId> 
<artifactId>font-awesome</artifactId> 
<version>4.6.3</version> 
</dependency> 

</dependencies> 

我懷疑的東西可能是錯誤的,我的pom.xml,或使用Tomcat 8.5,或別的東西。但沒有太多的...

提前致謝。

+0

你可以嘗試考慮[此鏈接](https://musingsinjava.wordpress.com/2014/11/02/enabling-jsf -2-2-and-cdi-1-2-on-tomcat-8 /) – deosha

+0

使用tommee ...方式更容易 – Kukeltje

+0

這個例外是無益的。這基本上是一個總結異常,告訴我們WAR無法部署。您應該進一步閱讀服務器日誌以查找實際導致部署失敗的根本原因異常。這部分代表了你的問題的答案。 – BalusC

回答

0

SOLUTION

似乎圖書館失蹤,Java註解的索引或Jandex,我已經嘗試過,但沒有明顯的正確途徑。不是正確的庫集合和/或不是正確的範圍。

之後申請以下

<dependency> 
    <groupId>org.jboss</groupId> 
    <artifactId>jandex</artifactId> 
    <version>1.2.4.Final</version> 
</dependency> 

似乎開始工作的罰款此配置

加的依賴。

所以,我的pom.xml的相關部分是:

<dependency> 
    <groupId>javax</groupId> 
    <artifactId>javaee-web-api</artifactId> 
    <version>7.0</version> 
    <scope>provided</scope> 
</dependency> 

<dependency> 
    <groupId>javax.enterprise</groupId> 
    <artifactId>cdi-api</artifactId> 
    <version>1.2</version> 
    <scope>provided</scope> 
</dependency> 

<dependency> 
    <groupId>org.jboss.weld.servlet</groupId> 
    <artifactId>weld-servlet</artifactId> 
    <version>2.3.5.Final</version> 
    <scope>runtime</scope> 
</dependency> 

<dependency> 
    <groupId>org.jboss</groupId> 
    <artifactId>jandex</artifactId> 
    <version>1.2.4.Final</version> 
</dependency>