Java EE 6: Target Unreachable, identifier 'helloBean' resolved to null [duplicate]

走远了吗. 提交于 2019-11-27 22:05:54

You need to have a JSF 2.0 compliant /WEB-INF/faces-config.xml file in order to get JSF to interpret the annotations.

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    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-facesconfig_2_0.xsd"
    version="2.0">

    <!-- Config here. Can even be kept empty. -->

</faces-config>

If you already have one or if that doesn't solve the problem, please pay attention to server startup logs if you don't see any warnings/errors.

By the way, your /WEB-INF/web.xml file is declared conform Servlet 2.5 specification. While this may not necessarily harm, it makes no sense if you're using a Servlet 3.0 compliant container. Update the root declaration as follows:

<?xml version="1.0" encoding="UTF-8"?>
<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">

    <!-- Config here. -->

</web-app>

The /WEB-INF/beans.xml is intented for CDI annotations like @Named, @Inject and so on. Just a completely empty file is sufficient to turn it on. It has totally no relationship to JSF annotations like @ManagedBean, @ManagedProperty and so on. It should also not be confused/mixed with each other.

I've been stuck with such a problem for half a day. The problem in my case appears only when I do run the WebApp from Eclipse. JSF 2 looks in WEB-INF/classes for annotated beans and doesn't find them. To solve this I've changed build output path to WebContent/WEB-INF/classes. Here is detailed explanation of similar case: Jetty maven goal jetty:run does not work with JSF 2.0 @ManagedBean

In the exact same scenario as OP (with eclipse, publishing to a Glassfish 3 server using run -> run on server) I get exactly the same error until removing spaces from the eclipse Project Name. Simply removing any spaces solved the problem.

I had the same problem, i tried everything. After that, i just clicked "Click and Build Project" button, "Build Project" button and resarted GlassFish server. After, it works to me, for now :)

Please you check your war file and see if your classes are under WEB-INF/classes folder. I ran into the same problem and found out there are no class files WEB-INF/classes folder.

Include @Named in your Controller/Bean..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!