Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Bean不在JNDI中_Java_Spring_Spring Mvc_Jboss_Jndi - Fatal编程技术网

Java Bean不在JNDI中

Java Bean不在JNDI中,java,spring,spring-mvc,jboss,jndi,Java,Spring,Spring Mvc,Jboss,Jndi,我创建了一个小型web服务(测试),但无法将其部署到jboss服务器。它可能与以下文件之一有关,这是my web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLoc

我创建了一个小型web服务(测试),但无法将其部署到jboss服务器。它可能与以下文件之一有关,这是my web.xml:

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

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/testing/*</url-pattern>
    </servlet-mapping>

</web-app>
我已尝试添加
同时发送到控制器和根上下文,并获得相同的错误


有什么线索表明下一步该做什么(我想知道为什么我需要JNDI)?

JBoss正在尝试将资源(可能是EJB?)注入servlet或过滤器。注释有一个值为“userService”的名称字段。JBoss无法找到合适的资源来注入,并要求您通过“mappedName”属性指定资源在JNDI中的位置

如果EJB上的名称与资源注入的名称不匹配,就会发生这种情况。例如,以下内容不起作用:

在EJB上:
@无状态(name=“foo”)

在Servlet中:
@EJB(name=“bar”)私有MyBean MyBean

两个名称值必须相同

更多信息:


    • JBoss正在尝试将资源(可能是EJB?)注入servlet或过滤器。注释有一个值为“userService”的名称字段。JBoss无法找到合适的资源来注入,并要求您通过“mappedName”属性指定资源在JNDI中的位置

      如果EJB上的名称与资源注入的名称不匹配,就会发生这种情况。例如,以下内容不起作用:

      在EJB上:
      @无状态(name=“foo”)

      在Servlet中:
      @EJB(name=“bar”)私有MyBean MyBean

      两个名称值必须相同

      更多信息:


      …出了什么问题?除了“它没有启动”之外,请看错误消息可能会有所帮助。@Jeremy Heiler@duffymo抱歉更新了问题。tnx…出了什么问题?除了“它没有启动”之外,请看错误消息可能会有所帮助。@Jeremy Heiler@duffymo抱歉更新了问题。tnx@johnstok感谢您的快速响应,我已经检查了名称是否匹配,以下是我在服务实现类中不了解的内容,我得到了
      @service(“userService”)@Transactional
      ,而在我的控制器
      @Resource(name=“userService”)private userService userService
      中,这正是您描述的问题,但是两个userservices的名称是相同的。您的下一步可能是通过jmx控制台使用JNDIView JMXBean来查看用@Service注释的类在JNDI中的安装位置。尝试使用该路径作为mappedName,看看它是否有效。另外,请查看JBoss文档,查看资源注释的名称值如何映射到JNDI。@johnstok很抱歉打扰您,它似乎不在其中,请单击“列表”操作的“调用”按钮。;-)@约翰斯托克我更新了问题,不同的问题现在,如果你能看一下的话great@johnstok感谢您的快速响应,我已经检查了名称是否匹配,以下是我在服务实现类中得到的
      @service(“userService”)@Transactional
      ,以及我的控制器
      @Resource(name=“userService”)中不了解的内容private UserService UserService
      正是您描述的问题,但是两个UserService的名称完全相同。您的下一步可能是通过jmx控制台使用JNDIView JMXBean,查看用@Service注释的类在JNDI中的安装位置。尝试使用该路径作为mappedName,看看它是否有效。另外,请查看JBoss文档,查看资源注释的名称值如何映射到JNDI。@johnstok很抱歉打扰您,它似乎不在其中,请单击“列表”操作的“调用”按钮。;-)@约翰斯托克我更新了问题,不同的问题现在,如果你能看看,那将是伟大的
      <?xml version="1.0" encoding="UTF-8"?>
      <beans:beans xmlns="http://www.springframework.org/schema/mvc"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:beans="http://www.springframework.org/schema/beans"
          xsi:schemaLocation="
              http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
              http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
      
          <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
      
          <!-- Enables the Spring MVC @Controller programming model -->
          <annotation-driven />
      
          <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
          <resources mapping="/resources/**" location="/resources/" />
      
          <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
          <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
              <beans:property name="prefix" value="/WEB-INF/views/" />
              <beans:property name="suffix" value=".jsp" />
          </beans:bean>
      
          <!-- Imports user-defined @Controller beans that process client requests -->
          <beans:import resource="controllers.xml" />
      
      </beans:beans>
      
      <?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:mvc="http://www.springframework.org/schema/mvc"
          xmlns:context="http://www.springframework.org/schema/context"
          xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
              http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  
              http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
      
          <!-- This required so that Spring can recognize our annotated beans -->
          <context:annotation-config />
      
          <!-- Scans within the base package of the application for @Components to configure as beans -->
          <context:component-scan base-package="com.test.jd" />
      
      </beans>
      
      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'userService' is defined: not found in JNDI environment