2015-10-14 54 views
0

我认为this question与我的相关,但我不想将另一个jar添加到项目中。在JDevelper和Weblogic中使用@Named注释

我正在将netbeans和Glassfish中的java hello1 example (JEE7)(您将看到下面的一些修改)迁移到JDeveloper 12.1.3和Weblogic Server 12.1.3.0.0。我这样做是因为我需要用jsf启动一个项目,而且我需要这些IDE和服务器。问题是我不能在我的支持bean中使用带有@Named注释的CDI。

的库添加到我的项目是“JSP运行系统”,JSF 2.1和JSTL 1.2

的JDeveloper提示我“配置项目CDI”,所以它增加了一个新的图书馆,“语境与Dependendcy注射液”,和豆类WEB-INF目录下的.xml文件。

的beans.xml

<?xml version = '1.0' encoding = 'windows-1252'?> 
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd" 
     xmlns="http://java.sun.com/xml/ns/javaee"></beans> 

当我运行该项目的响应是空的“你好”,并且name属性没有显示,但没有错误。

如果我删除了“语境与Dependendcy注入”库和beans.xml的文件,那么它显示我以下错误:如果我使用@ManagedBean注释,而不是@Named标注的

Error 500--Internal Server Error 

javax.el.PropertyNotFoundException: //C:/Users/edbuitrago/.jdeveloper/system12.1.3.0.41.140521.1008/o.j2ee/drs/Batch/ViewControllerWebApp.war/index.xhtml @8,49 value="#{batch.name}": Target Unreachable, identifier 'batch' resolved to null 
    at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100) 
    at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95) 
    at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030) 
    at javax.faces.component.UIInput.validate(UIInput.java:960) 
    at javax.faces.component.UIInput.executeValidate(UIInput.java:1233) 
    at javax.faces.component.UIInput.processValidators(UIInput.java:698) 
    at javax.faces.component.UIForm.processValidators(UIForm.java:253) 
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1220) 
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1220) 
    at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1164) 
    at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76) 
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) 
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) 
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280) 
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254) 
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136) 
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:346) 
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25) 
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79) 
    at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:137) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:315) 
    at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:460) 
    at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:120) 
    at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:217) 
    at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:81) 
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79) 
    at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:220) 
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79) 
    at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27) 
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79) 
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3436) 
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3402) 
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) 
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120) 
    at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57) 
    at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2285) 
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2201) 
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179) 
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1572) 
    at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:255) 
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311) 
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:263) 

一切正常。任何建议将不胜感激,在此先感谢。

这里是我的代码

的index.xhtml

<?xml version='1.0' encoding='windows-1252'?> 
<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"> 
    <h:head></h:head> 
    <h:body> 
     <h:form> 
      <h2>Hello, my name is Duke. What's yours?</h2> 
      <h:inputText value="#{batch.name}"/> 
      <h:commandButton value="Send" action="response"/> 
     </h:form> 
    </h:body> 
</html> 

response.xhtml

<?xml version='1.0' encoding='windows-1252'?> 
<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"> 
    <h:head></h:head> 
    <h:body> 
     <h2>Hello #{batch.name}</h2> 
    </h:body> 
</html> 

Batch.java

package view.backing; 

import javax.faces.bean.ManagedBean; 
import javax.faces.bean.RequestScoped; 

import javax.inject.Named; 

@Named 
@RequestScoped 
public class Batch { 
    private String name; 

    public Batch(){ 

     } 
    public void setName(String name) { 
     this.name = name; 
    } 

    public String getName() { 
     return name; 
    } 

} 

的web.xml

<?xml version = '1.0' encoding = 'windows-1252'?> 
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
     version="3.0"> 
    <servlet> 
    <servlet-name>Faces Servlet</servlet-name> 
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
    <servlet-name>Faces Servlet</servlet-name> 
    <url-pattern>/*</url-pattern> 
    </servlet-mapping> 
    <session-config> 
     <session-timeout> 
      30 
     </session-timeout> 
    </session-config> 
    <welcome-file-list> 
     <welcome-file>/index.xhtml</welcome-file> 
    </welcome-file-list> 
</web-app> 

项目结构

ViewController 
    |-src 
    | |-view 
    |  |-backing 
    |    |-Batch.java 
    |-public_html 
    |   |-index.xhtml 
    |   |-response.xhtml 
    |   |-WEB-INF 
    |     |-web.xml 
+0

使用'@ Named'使用'import javax.enterprise.context.RequestScoped' – Geinmachi

+0

我更改了导入,但显示了同样的错误。 “目标无法访问,标识符'批'解析为空” – Edu

+0

非常感谢!在你建议我和添加库“Contexts and Dependendcy Injection”之后,它的作用就像一个魅力。这是一个noob错误。这里是另一个相关的问题[链接](http://stackoverflow.com/questions/30128395/identifying-and-solving-javax-el-propertynotfoundexception-target-unreachable) – Edu

回答