【问题标题】:how i can tell glassfish about my spring dependancy injection?我如何告诉 glassfish 我的 spring 依赖注入?
【发布时间】:2015-01-22 21:20:32
【问题描述】:

我是新来的,我正在开发一个使用 hibernate 和 spring 依赖注入以及 SOAP Web 服务的项目。

我的问题是当我使用这个类在控制台中运行我的项目时:

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring-beans.xml");
    IServicesPharmacie pharmacieService = (IServicesPharmacie) context.getBean("service");
    context.close();
    Endpoint.publish("http://localhost:3597/Pharmacies", pharmacieService);
    System.out.println("The service has been published with success!");

我的项目工作正常,因为这 3 行:

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring-beans.xml");
    IServicesPharmacie pharmacieService = (IServicesPharmacie) context.getBean("service");
    context.close();

我可以讲述我的 spring 依赖注入。

但是我不知道如何在 glassfish 服务器上运行我的项目,并告诉他我的 spring 依赖注入,我想我最有一个 web.xml !!!!

我的 spring-beans.xml 是这样的:

<bean class="dao.PharmImpl" id="dao"></bean>

<bean class="metier.PharMetier" id="metier">
    <property name="phardao" ref="dao"></property>
</bean>

<bean class="services.ServicesPharmacie" id="service">
    <property name="servmetier" ref="metier" />
        </bean>
 </beans>

【问题讨论】:

    标签: java spring dependency-injection glassfish server


    【解决方案1】:

    您需要配置一个ContextLoaderListener 以在您的应用程序中引导spring。如下:

    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    

    也许如果你使用的是 springMVC,它的做法如下:

    <servlet>
            <servlet-name>springServlet</servlet-name>
            <servlet-class>
                org.springframework.web.servlet.DispatcherServlet
            </servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>springServlet</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
    

    请注意 URL 模式基于您的要求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-07
      • 2018-11-21
      • 2012-12-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多