我尝试将bean注入portlet。两者都位于分离的项目中。 我使用JBoss 7.1.1和Liferay6.2 SDK。这是我能想象到的最简单的场景,但我仍然遇到这个错误。如果bean在同一场战争中被定位,它可以正常工作。
错误:
10:31:30,704 ERROR [org.jboss.msc.service.fail](MSC服务主题1-8)MSC00001:无法启动服务jboss.deployment.unit。“DWPortlet1-portlet.war”.WeldService:服务jboss.deployment.unit中的org.jboss.msc.service.StartException。“DWPortlet1-portlet.war”.WeldService:org.jboss.weld.exceptions.DeploymentException:WELD-001408带有限定符的类型[Calc]的不满意依赖项[ @Default]在注入点[[field] @Inject private de.pao.bean.DWPortletController.calc] 在org.jboss.as.weld.services.WeldService.start(WeldService.java:83) at org.jboss.msc.service.ServiceControllerImpl $ StartTask.startService(ServiceControllerImpl.java:1811)[jboss-msc-1.0.2.GA.jar:1.0.2.GA] at org.jboss.msc.service.ServiceControllerImpl $ StartTask.run(ServiceControllerImpl.java:1746)[jboss-msc-1.0.2.GA.jar:1.0.2.GA] at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)[rt.jar:1.7.0_51] at java.util.concurrent.ThreadPoolExecutor $ Worker.run(Unknown Source)[rt.jar:1.7.0_51] 在java.lang.Thread.run(未知来源)[rt.jar:1.7.0_51] 引起:org.jboss.weld.exceptions.DeploymentException:WELD-001408在注入点[[field] @Inject private de.pao.bean.DWPortletController.calc]中带有限定符[@Default]的[Calc]类型的不满意依赖项 在org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:275) 在org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:244) 在org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:107) 在org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:127) 在org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:346) 在org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:331) 在org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:366) 在org.jboss.as.weld.WeldContainer.start(WeldContainer.java:83) 在org.jboss.as.weld.services.WeldService.start(WeldService.java:76) ......还有5个
豆:
> package com.test;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
@Stateless
@LocalBean
public class Calc {
public Calc() {
}
public int add(int a, int b) {
return a+b;
}
public int mult(int a, int b) {
return a*b;
}
}
的Portlet:
>
package de.pao.bean;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.inject.Inject;
import org.jboss.logging.Logger;
import com.test.Calc;
@ManagedBean
@RequestScoped
public class DWPortletController implements Serializable {
private static final Logger log = Logger.getLogger("1234");
private static final long serialVersionUID = 2056281697556539581L;
@Inject private Session0Bean sb0;
@Inject private Calc calc;
public DWPortletController() {
// TODO Auto-generated constructor stub
}
public void buttonAction() {
log.info("Hallo");
sb0.sayHello();
log.info("2+2 = " + calc.add(2, 2));
}
}
jboss-deployment-strucutre.xml:(在/ portlet / docroot / WEB-INF下):
<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
<deployment>
<exclusions>
<module name="javaee.api" />
<module name="org.apache.log4j" />
</exclusions>
<dependencies>
<module name="com.liferay.portal" />
<module name="javax.annotation.api" />
<module name="javax.enterprise.api" />
<module name="javax.inject.api" />
<module name="javax.interceptor.api" />
<module name="javax.validation.api" />
<module name="javax.mail.api" />
<module name="org.jboss.modules" />
<module name="deployment.BeanLogic.jar" />
</dependencies>
</deployment>
</jboss-deployment-structure>
常春藤XML:
<?xml version="1.0"?>
<ivy-module
version="2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"
>
<info module="portlet_primefaces_tmpl" organisation="com.liferay" />
<dependencies defaultconf="default">
<dependency name="jboss-el" org="org.jboss.el" rev="2.0.1.GA" />
<dependency name="jsf-api" org="com.sun.faces" rev="2.1.27" />
<dependency name="jsf-impl" org="com.sun.faces" rev="2.1.27" />
<dependency name="liferay-faces-bridge-api" org="com.liferay.faces" rev="3.2.4-ga5" />
<dependency name="liferay-faces-bridge-impl" org="com.liferay.faces" rev="3.2.4-ga5" />
<dependency name="liferay-faces-portal" org="com.liferay.faces" rev="3.2.4-ga5" />
<dependency name="liferay-faces-util" org="com.liferay.faces" rev="3.2.4-ga5" />
<dependency name="cdi-portlet-bridge-shared" org="com.liferay.cdi" rev="6.2.0.2" />
<dependency name="primefaces" org="org.primefaces" rev="4.0" />
<dependency org="org.jboss.weld" name="weld-api" rev="1.1.Final" />
<dependency org="org.jboss.weld" name="weld-core" rev="1.1.16.Final" />
<dependency org="org.jboss.weld" name="weld-spi" rev="1.1.Final" />
</dependencies>
</ivy-module>
我做错了什么?