Tomcat资源工厂org.apache.openejb.OpenEJBException:没有可用于resource-env-ref的提供程序

时间:2013-04-06 17:14:59

标签: java tomcat apache-tomee

我使用TomEE作为Application Server。 TomEE使用Tomcat 7.我有以下代码:

package com.jndi;

import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NamingException;
import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;


public class GitObjectFactory implements ObjectFactory {

public GitObjectFactory() {

}

public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable     environment) throws NamingException {
    GitConnection gitConnection = new GitConnection();
    // Customize the bean properties from our attributes
    Reference ref = (Reference) obj;
    RefAddr refAddr = ref.get("gitLocation");
    String value = (String) refAddr.getContent();
    gitConnection.setGitLocation(value);
    return gitConnection;
}
}

public class GitConnection {

private String gitLocation;

public GitConnection() {

}

public String getGitLocation() {
    return gitLocation;
}

public void setGitLocation(String gitLocation) {
    this.gitLocation = gitLocation;
}
 }

in context.xml
<Context>

<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name='git/GitConnectionFactory' auth='Container'
type='com.jndi.GitConnection'
factory='com.jndi.GitObjectFactory'
gitLocation='C:\jGitClone\.git'/>
在web.xml中

   http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd”          版本= “2.5” &GT;

     <context-param>
        <!-- Specifies the list of Spring Configuration files in comma separated format.-->

        /WEB-INF/spring/email.xml
     </context-param>

     <listener>
        <!-- Loads your Configuration Files-->
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
     </listener>

     <servlet>
        <servlet-name>i</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
     </servlet>

     <servlet-mapping>
        <servlet-name>i</servlet-name>
        <url-pattern>/</url-pattern>
     </servlet-mapping>

     <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
     </welcome-file-list>

     <resource-env-ref>
        <description>Object Factory for GitConnection instances.</description>
        <resource-env-ref-name>git/GitConnectionFactory</resource-env-ref-name>
        <resource-env-ref-type>com.jndi.GitConnection</resource-env-ref-type>
     </resource-env-ref>     
 </web-app>

When I load Tomcat, I can see successfully that the resource git/GitConnectionFactory is registered:

 INFO: Configuring Service(id=git/GitConnectionFactory, type=Resource, provider-id=ProvidedByTomcat)

06-Apr-2013 17:54:25 org.apache.openejb.assembler.classic.Assembler createRecipe

部署应用程序后,我会收到以下异常:

  org.apache.openejb.OpenEJBException: No provider available for resource-env-ref 'git/GitConnectionFactory' of type 'com.jndi.GitConnection' for 'i'.

问题出在哪里?

0 个答案:

没有答案