1

I am trying to set up jsf 2.3 on tomcat 8 whenever I used @inject I keep having an error with it I have googled and searched on stackoverflow.com yet I can't find a solution to it. I have already installed CDI (Weld) on it following @BalusC example from here How to install and use CDI on Tomcat? yet I keep having unsatisfied dependency: no bean matches the injection point. I can't figure it out is there anything i am missing?

ConfigurationBean.java

import static javax.faces.annotation.FacesConfig.Version.JSF_2_3;
import javax.faces.annotation.FacesConfig;
@FacesConfig(
     // Activates CDI build-in beans
     version = JSF_2_3
)
public class ConfigurationBean {
}

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"
  version="1.1" bean-discovery-mode="all">
</beans>

faces-config.xml

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.3"
  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/web-facesconfig_2_3.xsd">
</faces-config>

PushBean.java

@Named
@ViewScoped
public class PushBean implements Serializable {
  @Inject @Push(channel="counter") //This is where i get the error message unsatisfied dependency: no bean matches the injection point
  private PushContext push;
}

For me this code looks fine but am wondering if it is netbeans bug. I tried that without using spring just only tomcat with jsf i still get the same error message. I couldn't find any error message inside the stacktrace. Screen shot of the warning message in netbeans

  • 1
    pure Tomcat is not full JEE container, You can use TomEE – Jacek Cz Apr 30 '18 at 08:00
  • Sure you right. But it is possible to do that with JSF 2.2 using weld. So why can't it be possible with JSF 2.3? Anyway am using Spring and JSF with tomcat – Christian Ibanibo Apr 30 '18 at 08:06
  • How would netbeans be a part of the problem? Should not be too difficult to try without it... – Kukeltje May 03 '18 at 20:09
  • Am kinda confused here. I followed @BalusC teaching using JSF 2.2 and weld on tomcat yet i still get this error: unsatisfied dependency: no bean matches the injection point so i felt it was netbeans bug. – Christian Ibanibo May 03 '18 at 22:29
  • What is your JSF implementation and x.y.z version? See https://github.com/javaserverfaces/mojarra/pull/4277/commits/9662b559a51efa9224cfcc56c1277520d3c2a8ca – Kukeltje May 31 '18 at 14:35
  • Am using Mojarra implementation. I have tried 2.2, 2.3.0, 2.3.1, 2.3.3 versions – Christian Ibanibo Jun 01 '18 at 07:57

2 Answers2

2

Spring is NOT a full blown CDI container and only 'knows' the @Named and @Inject annotations and consequently does not (most likely) recognize the @Push annotation as a qualifier and cannot find the bean and throws the error you get (posting an explicit error and stacktrace is btw something you should always do in a question!)

See also:

Kukeltje
  • 11,924
  • 4
  • 19
  • 44
  • Apart from spring am still having the same error using only Tomcat. I followed @BalusC post accordingly yet i still get the error message - unsatisfied dependency when using Inject. I can't figure out what am missing. – Christian Ibanibo May 07 '18 at 09:58
  • Have you seen this link https://github.com/payara/patched-src-mojarra. Mojarra installation on servlet containers (Tomcat, Jetty, etc) – Christian Ibanibo May 07 '18 at 11:43
  • no but where are your comments about you using Spring? – Kukeltje May 07 '18 at 12:17
  • My comment is under my question. But this is not the real issue here, we can use Spring and JSF together. According to the links i shared, with Weld servlet it is possible to use CDI on Tomcat but am having issues with Inject, prompting this error message - unsatisfied dependency. The issue here is this error message. How am i going to fix it? I tried it with Tomcat 9 same issue. Please i need help. I read from stackoverflow that OmniFaces can also work on Tomcat, i tried it still got the same error message when i used Inject on pushContext – Christian Ibanibo May 07 '18 at 15:56
  • From my post, the last sentence, i said I tried it only on Tomcat without using Spring i got the same error message, i also tested it on Tomcat 9, i still got the same error message. The funniest thing is, it deployed well using netbeans 8.2 but you will see the error message on the line numbers and the PushContext doesn't work – Christian Ibanibo May 07 '18 at 23:12
  • NetBeans will show the warning: "Unsatisfied dependency: no bean matches the injection point – Christian Ibanibo May 07 '18 at 23:15
-1

I'd suggest to check your scopes. The built - in CDI scopes are @ApplicationScoped, @SessionScoped, @ConversationScoped and @RequestScoped . There is no @ViewScoped annotation in CDI. You can inject the same level or broader scope, but not one which is smaller (e.g you cannot inject @RequestScoped into @SessionScoped bean)

Helmwag
  • 420
  • 4
  • 6
  • ViewScoped (when used from the correct package) is a CDI compatible scope (The error is **not** on the scope but on the @Inject with the @Push) – Kukeltje May 29 '18 at 13:00