Dependency Injection Failing

Hi,
I am trying to inject instance of class "SaveCardInfoDAO" into ejb method "insertCardInfo". Following are the code snippets.
Controller (Stateless session bean in Project1)
     * Exposed Message to insert the Credit Card Info into the database.
@TransactionAttribute(TransactionAttributeType.REQUIRED)
     public void insertCardInfo(CreditCardDO ccdo){
     SaveCardInfoDAO saveCardInfo = (SaveCardInfoDAO) ApplicationUtil.getSpringContext().getBean("saveCardInfo");
     //SaveCardInfoDAO saveCardInfo = new SaveCardInfoDAO(ccsDataSource);
          try{
               saveCardInfo.openConnection(false);
               saveCardInfo.insertCardInfo(ccdo);
               System.out.println("Insert Success !!!");
          catch(SQLException e){
               ejbContext.setRollbackOnly();
               System.out.println("Insert Failure !!!");
          finally{
               saveCardInfo.closeConnection();
ApplicationUtil class (Initializes the Application context) project2.
public class ApplicationUtil {
     private static final ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
     static{
          init();
     public static void init(){
          DOMConfigurator.configure("resource/ccslogger.xml");
     public static ApplicationContext getSpringContext(){
          return context;
applicationContext.xml (in project2)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:aop="http://www.springframework.org/schema/aop"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<aop:aspectj-autoproxy />
<bean id="creditCardAdvice" class="com.fedex.ccs.advice.CCSCreditCardInfoAdvice" />
<bean id="saveCardInfo" class="com.fedex.ccs.dao.SaveCardInfoDAO" />
<bean id="creditCardDO" class="com.fedex.ccs.domain.CreditCardDO" />
</beans>
SaveCardInfoDAO (in project 3)
public class SaveCardInfoDAO extends CCSBaseDAO {
     private PreparedStatement stmt;
     public void setPreparedStatement() throws SQLException{
          stmt=getConnection().prepareStatement(SQLQueriesBase.CCS_Credit_Card_Info.INSERT_CREDIT_CARD_INFO);
     public PreparedStatement getPreparedStatement(){
          return stmt;
     public SaveCardInfoDAO(){
     public SaveCardInfoDAO(DataSource ccsDataSource){
          super(ccsDataSource);
     * Insert credit card information into the database table.
     * @param ccdo
     * @throws SQLException
     public int insertCardInfo(CreditCardDO ccdo)throws SQLException{
          setPreparedStatement();
          stmt.setObject(1, ccdo.getCreditCardType(), Types.VARCHAR);
          stmt.setObject(2, ccdo.getCreditCardID(), Types.VARCHAR);
          stmt.setObject(3, ccdo.getCreditCardBIN(), Types.VARCHAR);
          stmt.setObject(4, ccdo.getCreditCardExpDt(), Types.VARCHAR);
          stmt.setObject(5, ccdo.getAccountNumber(), Types.VARCHAR);
          int result = stmt.executeUpdate();
          stmt.close();
          return result;
Project 1 has dependency on project 2 and project 3.
Project 3 has dendency on Project 2
This gives me following error.
javax.ejb.EJBTransactionRolledbackException: EJB Exception: : java.lang.NoClassDefFoundError: com/fedex/ccs/util/ApplicationUtil
     at com.fedex.ccs.ejb.session.Controller.insertCardInfo(Controller.java:44)
Please help me resolve this issue. Let me know if you need something else.

Hi, Thanks for the reply.
I was trying to integrate Spring AOP and AspectJ (for logging) with EJB 3.0 in a wrong way. Now I have got idea as to what is the approach. But still I am getting a new error. The advice class bean mentioned in the spring AOP config file is giving me following error saying that it cannot find the specified advice class. But it can inject the DAO class instance that is in the same project as the Advice class.
Caused By: java.lang.NoClassDefFoundError: Could not initialize class com.fedex.ccs.advice.CCSCreditCardInfoAdvice
     at sun.reflect.GeneratedConstructorAccessor112.newInstance(Unknown Source)
     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
     at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
     at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
     at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:74)
     Truncated. see log file for complete stacktrace
If in my AOP config xml file I remove the bean definition of Advice class that it works fine and it injects DAO. But there is no logging done. Can you give me an headstart as to what is the appropriate way of integrating Spring AOP and AspectJ with EJB 3.0.
Thanks and Regards
Damodar

Similar Messages

  • EJB 3.0 Why Dependency Injection doesn't work?

    Hello Every body,
    i have a serious problem with dependency injection with EJB 3.0. I have tried so many time to get the simple sun delivered samples ejb-Applications working in NetBeans IDE, but they don't. After importing in building the projects in NetBeans, i get a NullPointerException while trying to run them. Is there any body who have experience with this? What am i making wrong?
    I searched for an answer since several days in google without any success. I have not found a single satisfactory explanation. I can't explain why even the examples in the java ee tutorials don't work.
    Please, can somebody help? I would very greatful.
    Cheers
    flips
    Here is an example of application (that don't work because the injection failed):
    * This is the business interface for Confirmer enterprise bean.
    @Remote
    public interface Confirmer {
    void sendNotice(String recipient);
    @Stateless
    public class ConfirmerBean implements Confirmer {
    private static final String mailer = "JavaMailer";
    private static Logger logger = Logger.getLogger(
    "confirmer.ejb.ConfirmerBean");
    @Resource(name = "mail/myMailSession")
    private Session session;
    /** Creates a new instance of ConfirmerBean */
    public ConfirmerBean() {
    public void sendNotice(String recipient) {
    try {
    Message message = new MimeMessage(session);
    message.setFrom();
    message.setRecipients(
    Message.RecipientType.TO,
    InternetAddress.parse(recipient, false));
    message.setSubject("Test Message from ConfirmerBean");
    DateFormat dateFormatter = DateFormat.getDateTimeInstance(
    DateFormat.LONG,
    DateFormat.SHORT);
    Date timeStamp = new Date();
    String messageText = "Thank you for your order." + '\n'
    + "We received your order on "
    + dateFormatter.format(timeStamp) + ".";
    message.setText(messageText);
    message.setHeader("X-Mailer", mailer);
    message.setSentDate(timeStamp);
    // Send message
    Transport.send(message);
    logger.info("Mail sent to " + recipient + ".");
    } catch (MessagingException ex) {
    ex.printStackTrace();
    logger.info("Error in ConfirmerBean for " + recipient);
    * @author ie139813
    public class ConfirmerClient {
    @EJB
    private static Confirmer confirmer;
    /** Creates a new instance of ConfirmerClient */
    public ConfirmerClient() {
    * @param args the command line arguments
    public static void main(String[] args) {
    String recipient = null;
    if (args.length == 1) {
    recipient = args[0];
    } else {
    recipient = "[email protected]";
    try {
    confirmer.sendNotice(recipient);
    System.out.println("Message sent to " + recipient + ".");
    System.exit(0);
    } catch (Exception ex) {
    ex.printStackTrace();
    }

    Try rebooting your computer. I had something similar. I rebooted my computer and it finished the update. Good luck!

  • Dependency injection in a Bean (MVC)

    Hello,
    Is it possible to use dependency injection in a bean (MVC architecture) ?
    I use it in a servlet, but I failed to use it in a bean !
    Thank you for your help.

    depends on which JEE specification you use. JEE6 has the CDI specification which can do what you want. JEE5 can only do dependency injection in "know server resources", such as servlets, EJBs, MDBs and JSF backing beans. Note that CDI is separated from the specification and thus can be used without having a JEE6 capable server; look into "Weld" which is the reference implementation of the CDI specification.
    http://www.seamframework.org/Weld
    Before CDI there was the Spring framework that could do it by the way, so that is also something that is worth investigating.

  • Problem in dependency injection with Jboss4.2.1

    Hi,
    I have an application that uses an EJB named -JBejbBean(SLSB)
    which implements a remote interface JBejb.
    I have used JDeveloper 10.1.3 IDE for developing it.
    JBejbBean contains a method
    public String show()
    return "hello";
    Now at the viewController side
    I have a JSF page whose backing bean ---view.backing.Start--- that looks up the above EJB using dependency injection as follows
    @EJB(mappedName="current-ejb-ear/JBejb/remote")
    private JBejb obj;
    this returns an exception that says .....
    Injection on Backing bean failed .
    javax.naming.NameNotFoundException:view.backing.Start not bound.

    Hi All,
    I just got an e-mail from Zinio:
    Hello,
    Thanks for contacting Zinio Customer Support.
    We have fixed the problem that was causing your magazine to appear blue in areas that should not have been blue. We’re very sorry for the inconvenience.
    Thank you,
    Emilia
    Zinio Customer Support
    After removing the bad issues and downloading them again, the problem was fixed, everything looks fine now! Unfortunatly it is not clear how this was fixed, there has been an update of the Zinio app (1.9.3) but the list of updates and fixes did not mention this problem.
    I'm very happy this has been addressed in relatively short time and that this problem in particular didn't need an update of the iOS.
    Hopefully the same will be true for all other apps having this PDF rendering issue.

  • Dependency Injection Problem in EJB 3.0

    Hello.
    I've been trying to get an example of java dependency injection working in JBoss 4.0.5.GA. I've installed it with EJB 3.0 support.
    The problem is that if I try to use the injected resource, I get a null pointer exception.
    The example I'm trying is a very short and simple one. Shouldn't be hard to figure out what is going wrong. Here it goes:
    [root]\src\hello\MessageServlet.java:
    package hello;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.List;
    import java.util.ListIterator;
    import javax.naming.InitialContext;
    import javax.annotation.*;
    public class MessageServlet extends HttpServlet {
         @Resource (mappedName="java:/DefaultDS")
         javax.sql.DataSource ejb30DB;
         public void init () throws ServletException {
         public void service(HttpServletRequest request, HttpServletResponse response)
                   throws IOException, ServletException {
              boolean injectedLookingGood = false;
              boolean notInjectedLookingGood = false;
              try {
                   java.sql.Connection conn = ejb30DB.getConnection();
                   conn.close();
                   injectedLookingGood = true;
              } catch(Exception e) {
                   e.printStackTrace();
              try {
                   InitialContext ic = new InitialContext();
                   javax.sql.DataSource ds = (javax.sql.DataSource)ic.lookup("java:/DefaultDS");
                   java.sql.Connection conn = ds.getConnection();
                   conn.close();
                   notInjectedLookingGood = true;
              } catch(Exception e) {
                   e.printStackTrace();
              response.setContentType("text/html");
              ServletOutputStream out = response.getOutputStream();
              out.println("<html>");
              out.println("<head><title>Hello World</title></head>");
              out.println("<body>");
              out.println("<h1>Hello World</h1>");
              out.println("<form action=\"HelloWorld\" method=\"get\">");
              out.print("Injected DataSource is looking ");
              if(injectedLookingGood) {
                   out.println("good <br>");
              else {
                   out.println("bad <br>");
              out.print("Not-Injected DataSource is looking ");
              if(notInjectedLookingGood) {
                   out.println("good <br/>");
              else {
                   out.println("bad <br/>");
              out.println("<input type=\"submit\" value=\"Test Some More\">");
              out.println("</form>");
              out.println("</body>");
              out.println("</html>");
    [root]\etc\META-INF\web.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
    <web-app>
    <display-name>HelloWorldWAR</display-name>
    <servlet>
    <display-name>HelloWorld</display-name>
    <servlet-name>HelloWorldServlet</servlet-name>
    <servlet-class>hello.MessageServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloWorldServlet</servlet-name>
    <url-pattern>/servlet/HelloWorld</url-pattern>
    </servlet-mapping>
    </web-app>
    [root]\etc\META-INF\application.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <application xmlns="http://java.sun.com/xml/ns/j2ee" version="1.4"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com /xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
    <display-name>HelloWorld</display-name>
    <description>Application description</description>
    <module>
    <web>
    <web-uri>web-ejb3.war</web-uri>
    <context-root>HelloWorld</context-root>
    </web>
    </module>
    </application>
    [root]\build.xml:
    <project name="HelloWorld" default="all" basedir=".">
    <!-- Name of project and version -->
    <property name="proj.name" value="HelloWorld"/>
    <property name="proj.version" value="1.0"/>
    <!-- Global properties for thid build -->
    <property name="src.dir" value="${basedir}/src"/>
    <property name="build.dir" value="${basedir}/bin"/>
    <property name="lib.dir" value="${basedir}/lib"/>
    <property name="build.classes.dir" value="${build.dir}/classes"/>
    <property name="build.jar.dir" value="${build.dir}/jar"/>
    <property name="src.etc.dir" value="${basedir}/etc"/>
    <property name="meta-inf.dir" value="${src.etc.dir}/META-INF"/>
    <!-- The build classpath -->
    <path id="build.classpath">
    <fileset dir="${lib.dir}">
    <include name="**/*.jar"/>
    <include name="**/*.zip"/>
    </fileset>
    </path>
    <!-- Useful shortcuts -->
    <patternset id="meta.files">
    <include name="**/*.xml" />
    <include name="**/*.properties"/>
    </patternset>
    <target name="prepare">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.classes.dir}"/>
    <mkdir dir="${build.jar.dir}"/>
    </target>
    <target name="compile" depends="prepare">
    <javac destdir="${build.classes.dir}"
    classpathref="build.classpath"
    debug="on">
    <src path="${src.dir}"/>
    </javac>
    </target>
    <target name="package-web" depends="compile">
    <war warfile="${build.dir}/jar/web-ejb3.war"
    webxml="${meta-inf.dir}/web.xml">
    <classes dir="${build.dir}/classes">
    <include name="**/*Servlet.class"/>
    </classes>
    </war>
    </target>
    <!-- Creates an ear file containing the web client war. -->
    <target name="assemble-app">
    <ear destfile="${build.jar.dir}/HelloWorld.ear" appxml="${meta-inf.dir}/application.xml">
    <fileset dir="${build.dir}/jar"
    includes="*.war"/>
    </ear>
    </target>
    <target name="clean">
    <delete dir="${build.dir}" />
    </target>
    <target name="all">
    <antcall target="clean" />
    <antcall target="package-web" />
    <antcall target="assemble-app" />
    </target>
    </project>
    Any help would be apreciated.
    Thanks in advance,
    Hugo Oliveira
    [email protected]

    Hello Ken.
    I gess dependency injection is unnavailable in servlets as of this moment. I conducted another test using a session bean that injects and tests the DataSource and a servlet calling the session bean via a refference obtained from InitialContext. It worked OK.
    Here's the code:
    [root]/src/hello/MessageHandler.java:
    package hello;
    public interface MessageHandler {
         public boolean testInjection();
    [root]/src/hello/MessageHandlerBean.java:
    package hello;
    import javax.ejb.Stateless;
    import javax.persistence.*;
    import java.util.List;
    import javax.annotation.*;
    @Stateless
    public class MessageHandlerBean implements MessageHandler {
         @Resource (mappedName="java:/DefaultDS")
         private javax.sql.DataSource ds;     
         public boolean testInjection() {
              try {
                   java.sql.Connection conn = ds.getConnection();
                   conn.close();
                   return true;
              } catch(Exception e) {
                   e.printStackTrace();
              return false;
    [root]/src/hello/MessageServlet.java:
    package hello;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.List;
    import java.util.ListIterator;
    import javax.naming.InitialContext;
    import javax.annotation.*;
    public class MessageServlet extends HttpServlet {
         public void init () throws ServletException {
         public void service(HttpServletRequest request, HttpServletResponse response)
                   throws IOException, ServletException {
              boolean injectedLookingGood = false;
              try {
                   InitialContext ic = new InitialContext();
                   MessageHandler mh = (MessageHandler)ic.lookup("HelloWorld/MessageHandlerBean/local");
                   injectedLookingGood = mh.testInjection();
              } catch(Exception e) {
                   e.printStackTrace();
              response.setContentType("text/html");
              ServletOutputStream out = response.getOutputStream();
              out.println("<html>");
              out.println("<head><title>Hello World</title></head>");
              out.println("<body>");
              out.println("<h1>Hello World</h1>");
              out.println("<form action=\"HelloWorld\" method=\"get\">");
              out.print("Injected DataSource is looking ");
              if(injectedLookingGood) {
                   out.println("good <br>");
              else {
                   out.println("bad <br>");
              out.println("<input type=\"submit\" value=\"Test Some More\">");
              out.println("</form>");
              out.println("</body>");
              out.println("</html>");
    [root]/etc/META-INF/application.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <application xmlns="http://java.sun.com/xml/ns/j2ee" version="1.4"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com /xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
    <display-name>HelloWorld</display-name>
    <description>Application description</description>
    <module>
    <ejb>HelloWorld.ejb3</ejb>
    </module>
    <module>
    <web>
    <web-uri>web-ejb3.war</web-uri>
    <context-root>HelloWorld</context-root>
    </web>
    </module>
    </application>
    [root]/etc/META-INF/web.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
    <web-app version="2.5" 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_2_5.xsd">
    <display-name>HelloWorldWAR</display-name>
    <servlet>
    <display-name>HelloWorld</display-name>
    <servlet-name>HelloWorldServlet</servlet-name>
    <servlet-class>hello.MessageServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloWorldServlet</servlet-name>
    <url-pattern>/servlet/HelloWorld</url-pattern>
    </servlet-mapping>
    </web-app>
    [root]/build.xml:
    <project name="HelloWorld" default="all" basedir=".">
    <!-- Name of project and version -->
    <property name="proj.name" value="HelloWorld"/>
    <property name="proj.version" value="1.0"/>
    <!-- Global properties for thid build -->
    <property name="src.dir" value="${basedir}/src"/>
    <property name="build.dir" value="${basedir}/bin"/>
    <property name="lib.dir" value="${basedir}/lib"/>
    <property name="build.classes.dir" value="${build.dir}/classes"/>
    <property name="build.jar.dir" value="${build.dir}/jar"/>
    <property name="src.etc.dir" value="${basedir}/etc"/>
    <property name="meta-inf.dir" value="${src.etc.dir}/META-INF"/>
    <!-- The build classpath -->
    <path id="build.classpath">
    <fileset dir="${lib.dir}">
    <include name="**/*.jar"/>
    <include name="**/*.zip"/>
    </fileset>
    </path>
    <!-- Useful shortcuts -->
    <patternset id="meta.files">
    <include name="**/*.xml" />
    <include name="**/*.properties"/>
    </patternset>
    <target name="prepare">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.classes.dir}"/>
    <mkdir dir="${build.jar.dir}"/>
    </target>
    <target name="compile" depends="prepare">
    <javac destdir="${build.classes.dir}"
    classpathref="build.classpath"
    debug="on">
    <src path="${src.dir}"/>
    </javac>
    </target>
    <target name="package-ejb" depends="compile">
    <jar jarfile="${build.jar.dir}/HelloWorld.ejb3">
    <fileset dir="${build.classes.dir}">
    <include name="**/*.class"/>
    </fileset>
    <!--
         <metainf dir="${meta-inf.dir}">
    <include name="persistence.xml"/>
    </metainf>
    -->
    </jar>
    </target>
    <target name="package-web" depends="compile">
    <war warfile="${build.dir}/jar/web-ejb3.war"
    webxml="${meta-inf.dir}/web.xml">
    <!--
    <fileset dir="web">
    <include name="**/*"/>
    </fileset>
    -->
    <!--
    <webinf dir="dd/web">
    <include name="jboss-web.xml"/>
    </webinf>
    -->
    <classes dir="${build.dir}/classes">
    <include name="**/*Servlet.class"/>
    </classes>
    </war>
    </target>
    <!-- Creates an ear file containing the ejb jars and the web client war. -->
    <target name="assemble-app">
    <ear destfile="${build.jar.dir}/HelloWorld.ear" appxml="${meta-inf.dir}/application.xml">
    <fileset dir="${build.dir}/jar"
    includes="*.ejb3,*.war"/>
    </ear>
    <!-- <delete file="${build.dir}/jar/web-ejb3.war"/>
    <delete dir="${build.dir}/classes"/> -->
    </target>
    <target name="clean">
    <delete dir="${build.dir}" />
    </target>
    <target name="all">
    <antcall target="clean" />
    <antcall target="package-ejb" />
    <antcall target="package-web" />
    <antcall target="assemble-app" />
    </target>
    </project>
    Thanks,
    Hugo Oliveira
    [email protected]

  • EJB 3.0 Dependency Injection and reentrant Calls on SFSB

    Hi there
    I have a SFSB (Bean A) that injects another SFSB (Bean B) with the @EJB annotation. Now Bean A does reentrant-calls on Bean B, which is ok, because it just asks for the current state.
    This results in a "javax.ejb.EJBTransactionRolledbackException: Illegal attempt to make a reentrant call to a stateful session bean from home: .....; nested exception is: javax.ejb.ConcurrentAccessException: Illegal attempt to make a reentrant call to a stateful session bean: ....."
    Now I added a weblogic-ejb-jar.xml with the section:
    <stateful-session-descriptor>
      <allow-concurrent-calls>true</allow-concurrent-calls>
    </stateful-session-descriptor>to enable reentrant calls on my SFSB. Unfortunatly this leads to problems with the DI, it simply doesnt work anymore!!! The message now is " java.lang.IllegalStateException: Cannot find object BeanBInterface with java:comp/env/ejb/BeanBInterface". Obviously the DI didn't work, the local variable isn't filled anmyore.
    Is this a bug of WLS 10.0 MP1 or a feature? Should I open a bug report? Any tips a welcome!
    Stephan

    There is currently no possiblity in Weblogic 10 server web layer to use Dependency Injection on any other component than the ones defined in web.xml s.a.:
    - servlets
    - listeners
    - filters
    See here:
    http://e-docs.bea.com/wls/docs100/webapp/annotateservlet.html
    A simple POJO class part of the web application (such as a Backing Bean in JSF or an Action in Struts for example) is not benefiting from DI.
    Doesn't this make Weblogic 10 a NON JEE 5 compliant server?
    Why was this restriction imposed?
    And how is one supposed to use DI with a simple POJO class? Why this huge inconvenience?

  • EJB 3.0 Dependency Injection in JSF ?

    Hi,
    I have a question about ejb 3.0 dependency injection in a JSF WebApp:
    I Build successfully a Web Module (version 2.5) an EJB Module (version 3.0) and an EAR Module (Version 5.0). The EAR App can be deployed without errors on a Bea WebLogic Server 10.1. All modules are successfully deployed.
    Inside the Web Module there is a Servlet which uses dependency injection to access the session EJB form the EJB Module. This works perfect.
    Next I try to use the same EJB with dependency injection from the JSF Page via a backing bean. But when I try to access my JSP Page I got a Nullpointer Exception.
    It seems that the Dependency Injection in the JSP App did not work?
    Can anybody give me a hint what could be wrong?
    Thanks
    Ralph

    There is currently no possiblity in Weblogic 10 server web layer to use Dependency Injection on any other component than the ones defined in web.xml s.a.:
    - servlets
    - listeners
    - filters
    See here:
    http://e-docs.bea.com/wls/docs100/webapp/annotateservlet.html
    A simple POJO class part of the web application (such as a Backing Bean in JSF or an Action in Struts for example) is not benefiting from DI.
    Doesn't this make Weblogic 10 a NON JEE 5 compliant server?
    Why was this restriction imposed?
    And how is one supposed to use DI with a simple POJO class? Why this huge inconvenience?

  • Types of dependency injection.

    Hi,
    I wanted to know some details about difference between setter and constructor based dependency injection(IOC)
    I didnt understood the foll things :
    1. "setter based IOC is good for object that take optional parameters and objects that need to change their parameters many times during their lifecycles." The object which is referred is the object to be injected ?
    2. In the Constructor based IOC "the creater knows about the referenced object".
    Providing links or giving simple examples would be appreciated.
    Thanks in advance.

    Hi,
    I wanted to know some details about difference
    between setter and constructor based dependency
    injection(IOC)
    I didnt understood the foll things :
    1. "setter based IOC is good for object that take
    optional parameters and objects that need to change
    their parameters many times during their lifecycles."
    The object which is referred is the object to be
    be injected ?Yes, what else would make sense?
    2. In the Constructor based IOC "the creater knows
    about the referenced object". Because the referenced object is a parameter in the constructor call.
    Providing links or giving simple examples would be appreciated.Martin Fowler's IoC article is the best explanation I've ever read:
    http://www.martinfowler.com/articles/injection.html
    %

  • Design Issue: Localization using Lookup OR Dependency Injection

    Hello Forums!
    I'm having a design issue regarding localization in my application. I'm using Spring Framework (www.springframework.org) as an
    application container, which provides DI (dependency injection) - but the issue is not Spring- but rather design related. All localization
    logic is encapsulated in a separate class ("I18nManager"), which basically is just a wrapper around multiple Java ResourceBundles.
    Right now localization is performed in the "traditional" look-up style, e.g.
    ApplicationContext.getMessage("some.message.key");
    where ApplicationContext is a wrapper around the Spring application context and getMessage(...) is a static method on that
    context. The advantage of that solution is a clean & simple interface design, localization merely becomes a feature of classes, but
    is not part of their public API. The only problem with that approach is the very tight coupling of Classes to the ApplicationContext, which
    really is a problem when you want to use code outside of an application context. The importance of this problem increases if one considers
    that I18N is a concern that can be found in every application layer, from GUI to business to data tier, all those components suddenly depdend
    on an application context being present.
    My proposed solution to this problem is a "Localizable" interface, which may provide mutators for an "I18NManager" instance that can be
    passed in. But is this really a well-designed solution, as almost any object in an application may be required to implement this interface?
    I'm too concerned about performance: the look-up solution does not need to pass references to localizable objects, whereas my proposed solution
    will require 1 I18NManager reference per localizable object, which might cause troubles if you let's say load 10.000 POJOs from some database that
    are all localizable.
    So (finally) my question: how do you handle such design issues? Are there any other solutions out there that I'm not aware of yet? Comments/Help welcome!

    michael_schmid wrote:
    Hello Forums!
    I'm having a design issue regarding localization in my application. I'm using Spring Framework (www.springframework.org) as an
    application container, which provides DI (dependency injection) - but the issue is not Spring- but rather design related. All localization
    logic is encapsulated in a separate class ("I18nManager"), which basically is just a wrapper around multiple Java ResourceBundles.Why do you think you need a wrapper around resource bundles? Spring does very well with I18N, as well as Java does. What improvement do you think you bring?
    Right now localization is performed in the "traditional" look-up style, e.g.
    ApplicationContext.getMessage("some.message.key");
    where ApplicationContext is a wrapper around the Spring application context and getMessage(...) is a static method on that
    context. Now you're wrapping the Spring app context? Oh, brother. Sounds mad to me.
    The advantage of that solution is a clean & simple interface design, localization merely becomes a feature of classes, but
    is not part of their public API. The only problem with that approach is the very tight coupling of Classes to the ApplicationContext, which
    really is a problem when you want to use code outside of an application context. The importance of this problem increases if one considers
    that I18N is a concern that can be found in every application layer, from GUI to business to data tier, all those components suddenly depdend
    on an application context being present.One man's "tight coupling" is another person's dependency.
    I agree that overly tight coupling can be a problem, but sometimes a dependency just can't be helped. They aren't all bad. The only class with no dependencies calls no one and is called by no one. We'd call that a big, fat main class. What good is that?
    Personally, I would discourage you from wrapping Spring too much. I doubt that you're improving your life. Better to use Spring straight, the way it was intended. I find that they're much better designers than I am.
    My proposed solution to this problem is a "Localizable" interface, which may provide mutators for an "I18NManager" instance that can be
    passed in. But is this really a well-designed solution, as almost any object in an application may be required to implement this interface?I would say no.
    I'm too concerned about performance: the look-up solution does not need to pass references to localizable objects, whereas my proposed solution
    will require 1 I18NManager reference per localizable object, which might cause troubles if you let's say load 10.000 POJOs from some database that
    are all localizable.
    So (finally) my question: how do you handle such design issues? Are there any other solutions out there that I'm not aware of yet? Comments/Help welcome!I would use the features that are built into Spring and Java until I ran into a problem. It seems to me that you're wrapping your way into a problem and making things more complex than they need to be.
    %

  • Dependency Injection - JAX-WS / Spring/ WebLogic 10.0.0

    I have an issue with Spring dependency injection not working in WebLogic 10.3.0.
    We are using WebLogic 10.3.2 (11gR1) in our development environment which uses technologies:
    JAX-WS web service and Spring.
    My webservice class extends SpringBeanAutowiringSupport to take care of the class loader issue of JAX-WS and spring because of which Spring dependency injection gets ignored.
    My problem is that our production environment has WebLogic 10.3.0. The same application war file when deployed here, DI gets ignored. Can anyone help me with this?

    Hi to all,
    I'm working with the new WebLogic 10.3 and I've the same problem.
    I can't configure JMS transport with JAX-WS and finally I always have the same problem.
    Have you found the problem (or a link/solution) ?
    Edited by: user7266092 on 04-Mar-2010 01:11

  • About Dependency Injection in EJB3.0

    Hi,
    I'm a fresh man in EJB3.0.
    Except @EJB and @Resource,is there
    any other anotation can be used to
    Dependency Injection?

    There is currently no possiblity in Weblogic 10 server web layer to use Dependency Injection on any other component than the ones defined in web.xml s.a.:
    - servlets
    - listeners
    - filters
    See here:
    http://e-docs.bea.com/wls/docs100/webapp/annotateservlet.html
    A simple POJO class part of the web application (such as a Backing Bean in JSF or an Action in Struts for example) is not benefiting from DI.
    Doesn't this make Weblogic 10 a NON JEE 5 compliant server?
    Why was this restriction imposed?
    And how is one supposed to use DI with a simple POJO class? Why this huge inconvenience?

  • Dependency injection nightmare

    I can't get it what is wrong...given this faces-config.xml
    <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_1_2.xsd"
         version="1.2">
         <application>
              <view-handler>com.icesoft.faces.facelets.D2DFaceletViewHandler</view-handler>
         </application>
         <managed-bean>
              <managed-bean-name>persistenceManager</managed-bean-name>
              <managed-bean-class>ro.sinoptix.controller.PersistenceManager</managed-bean-class>
              <managed-bean-scope>application</managed-bean-scope>
         </managed-bean>
         <managed-bean>
              <managed-bean-name>tipCerereCtrl</managed-bean-name>
              <managed-bean-class>ro.sinoptix.controller.TipCerereCtrl</managed-bean-class>
              <managed-bean-scope>session</managed-bean-scope>
              <managed-property>
                   <property-name>persistenceManager</property-name>
                   <property-class>ro.sinoptix.controller.PersistenceManager</property-class>
                   <value>#{persistenceManager}</value>
              </managed-property>
         </managed-bean>
         <managed-bean>
              <description>tine pagina TipuriCerere</description>
              <managed-bean-name>tipuriCerere</managed-bean-name>
              <managed-bean-class>ro.sinoptix.view.TipuriCerere</managed-bean-class>
              <managed-bean-scope>request</managed-bean-scope>
              <managed-property>
                   <property-name>tcl</property-name>
                   <property-class>ro.sinoptix.controller.TipCerereCtrl</property-class>
                   <value>#{tipCerereCtrl}</value>
              </managed-property>
         </managed-bean>
    </faces-config>i get this error
    SEVERE: JSF1054: (Phase ID: RENDER_RESPONSE 6, View ID: /TipuriCerere.xhtml) Exception thrown during phase execution: javax.faces.event.PhaseEvent[source=com.sun.faces.lifecycle.LifecycleImpl@7a36a2]
    SEVERE: Exception occured during rendering on http://localhost:8080/SOConfigManager/TipuriCerere.jsf [/TipuriCerere.xhtml]
    javax.faces.FacesException: Problem in renderResponse: com.sun.faces.mgbean.ManagedBeanPreProcessingException: Unexpected error processing managed bean tipuriCerere
    Caused by: com.sun.faces.mgbean.ManagedBeanPreProcessingException: Unexpected error processing managed bean tipuriCerere
         at com.sun.faces.mgbean.BeanManager.preProcessBean(BeanManager.java:356)
         at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:201)
         at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:86)
         at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
         at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
         at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:61)
         at org.apache.el.parser.AstValue.getValue(AstValue.java:107)
         at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
         at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
         at javax.faces.component.UIData.getValue(UIData.java:609)
         at com.icesoft.faces.component.panelseries.UISeries.getValue(UISeries.java:572)
         ... 65 more
    Caused by: com.sun.faces.mgbean.ManagedBeanPreProcessingException: Unexpected error processing managed property tcl
         at com.sun.faces.mgbean.ManagedBeanBuilder.bake(ManagedBeanBuilder.java:117)
         at com.sun.faces.mgbean.BeanManager.preProcessBean(BeanManager.java:311)
         ... 75 more
    Caused by: java.lang.NullPointerException
         at com.sun.faces.mgbean.ManagedBeanBuilder.bakeBeanProperty(ManagedBeanBuilder.java:350)
         at com.sun.faces.mgbean.ManagedBeanBuilder.bake(ManagedBeanBuilder.java:107)
         ... 76 morei cant figure out what is wrong ... my classes are
    public class TipuriCerere {
         // dependency injection
         private TipCerereCtrl tcl;
            public TipCerereCtrl getTcl() {
              return tcl;
    public class TipCerereCtrl {
         private PersistenceManager persistenceManager;
         public PersistenceManager getPersistenceManager() {
              return persistenceManager;
    }Any help is valueble to me
    Edited by: kquizak on Jan 8, 2010 1:54 AM

    r035198x wrote:
    gimbal2 wrote:
    .... Anybody else have an opinion about this?Definitely odd. Would have expected something like property not accessible.
    What JSF implementation and version is this?I just had this happen to me as well today. Added a ManagedProperty to a ViewScoped bean, like so:
         @ManagedProperty(value="#{actionStateMachine}")
         private ActionStateMachine     actionStateMachine;.. and only provided a getter, no setter, ... and I got the same exception shown by the OP.
    After I added a setter, the exception does not happen.
    Environment:
    JBoss 7.1.1
    Mojarra 2.1.7-jbossorg-1 (20120227-1401)

  • Dependency injection across enterprise applications is possible?

    Hi All ,
    I am working on EJB3.0. I want to know if we can use dependency injection across application?
    I have
    1.  jpadc  having all JPA classes and 1 jpaAppl enterprise application having only jpadc
    2.  session1dc and session1Appl enterprise application for session1dc
    3.  session2dc and session2Appl enterprise application for session2dc
    I want to use jpa classes and sesisonbean classes from jpadc and session2dc respectively
    inside session2dc. is it possible? i tried but i am not able to d odependency injection
    Please let me know if this is possible?
    Thnx in advance
    Regards
    Kavita

    Hi Kavita,
    Yes, you can use dependency injection. For more information, refer to this document:
    http://help.sap.com/saphelp_nwce711/helpdata/en/44/bf6e9344751eaae10000000a1553f6/frameset.htm
    If you need information related to the JPA part, read this:
    http://help.sap.com/saphelp_nwce711/helpdata/en/46/307a2a50094f09e10000000a114a6b/frameset.htm
    Best regards,
    Ekaterina

  • Dependency injection

    I have a query in EJB 3.0 dependency injection.
    here is a sample code:
    public class MyServlet extends HttpServlet {
          @EJB
          private HelloStateless hss; 
    ............................................hss needs to be an interface or bean class ?

    user575089 wrote:
    Yes, there's a reasonable case for that, avoiding the tedious JNDI lookup. JPA Entities aren't looked up from JNDIwhy ?Do you know what JNDI is? JPA entities are either retrieved from the database, or created as regular pojos before persisting them in the db. JNDI is no place for entities.
    What advantage would you have over "new MyPojo()"?probably nothing . I ask you the opposite what advantage do they get here ( without new MyPojo() style ) ?
    +public class MyServlet extends HttpServlet {+
    +@EJB+
    private HelloStateless hss;
    +............................................+
    +............................................+EJBs are no Pojos, so it's not at all the same thing. With @EJB you avoid the extra InitialContext creations and manual lookups with one simple annotation.

  • Dependency injection/annotation Error

    Greetings,
    Hello everybody !
    This topic's about a problem I'm currently experiencing while trying to deploy a Web Application that makes a call to an EJB using Dependency injection from a Servlet. This is the Stack trace generated when I attempt to deploy my web app:
    DeployerRunnable.run Error parsing annotation for class org.servlet.TestServletoracle.oc4j.admin.internal.DeployerException: Error parsing annotation for class org.servlet.TestServlet
    at oracle.oc4j.admin.internal.DeployerBase.execute(DeployerBase.java:126)
    at oracle.oc4j.admin.jmx.server.mbeans.deploy.OC4JDeployerRunnable.doRun(OC4JDeployerRunnable.java:52)
    at oracle.oc4j.admin.jmx.server.mbeans.deploy.DeployerRunnable.run(DeployerRunnable.java:81)
    at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
    at java.lang.Thread.run(Thread.java:619)
    Here's a Snippet from the Servlet that's making the call:
    *public class TestServlet extends HttpServlet {*
         *@EJB(beanName="MathEjbBean")*
         private org.logic.MathEjbBeanRemote ejb;
         protected void doGet(HttpServletRequest request,
                   *HttpServletResponse response) throws ServletException, IOException {*
              ejb.sum(1, 2);
    Here's the EJB implementation:
    *@Stateless*
    *@StatelessDeployment*
    *public class MathEjbBean implements MathEjbBeanRemote, MathEjbBeanLocal {*
         *@Override*
         *public int sum(int a, int b) {*
              *// TODO Auto-generated method stub*
              return a + b;
    Finally, I will post the Container-specific Deployment descriptor:
    <?xml version="1.0" encoding="utf-8"?>
    <orion-ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/orion-ejb-jar-10_0.xsd" deployment-version="" deployment-time="128f9bdc917" schema-major-version="10" schema-minor-version="0" >
    <enterprise-beans>
    <session-deployment name="MathEjbBean" tx-retry-wait="60" location="MathEjbBean" local-location="MathEJB_MathEjbBeanLocal" persistence-filename="MathEjbBean">
    </session-deployment>
    </enterprise-beans>
    <assembly-descriptor>
    <default-method-access>
    <security-role-mapping name="<default-ejb-caller-role>" impliesAll="true" />
    </default-method-access>
    </assembly-descriptor>
    </orion-ejb-jar>
    Up until this moment, I still have no clue, about the reason why I can't inject my EJB in the Web-app's Servlet.
    Please Help Me
    It's so hard to find information about this problem on the internet.
    Best Regards,
    Jose.

    Hello there !
    I've corrected this problem by using the same name for the @Stateless annotation and the display-name tag in the ejb-jar file, for @EJB this name should match also.
    Good Luck, hope this is helpful in the future.

Maybe you are looking for

  • "iPod cannot be synced. The required file is locked."

    I'm sure there are several threads about this, but none have produced an answer that works for me. I have an iPod Touch 1G and iTunes 8.0.1.11, though I don't think that matters. I should probably ask this on a Windows XP website, but I thought maybe

  • Help with wireless networking with my Photosmart 6525 on Mac 10.8.5

    I have just purchased an HP Photosmart 6525 and cannot get the wireless printing to work. I've followed all of the instructions provided online and printed with the device.  I'm attempting to connect from my Macbook Air running 10.8.5. I've successfu

  • VF04, Create DownPayment Request, No Accounting Document generated...

    Hi, all, I created a down payment request(FAZ) with VF04 for a Billing Plan, but the accounting document did generate, when I manually release to accounting, the message is 'The document is not relevant for accounting', would you pls advise what I ma

  • Report on selection-screen fields

    hi,     the selection-screen has the fields invoice number,invoice date and customer name. date is mandatory..now i have to fetch the data based on the selection. if only date is selected,then i have to print the entrie data from that date. how to  w

  • Playing dvd's on macbook air

    Is it possible to play dvd's using macbook air?