[Javalist] Spring kerdesek

cx.chico cx.chico at gmail.com
2012. Jún. 4., H, 21:20:18 CEST


Az Spring AOP alapban interfészeken keresztül működik. A @Autowired
használatához létre kell hozni egy interfészt. A program így
módosulna:

public interface PollingService {
       Response<Map<String, Pojo>> start();
       void reset();
}

@Component
@Scope("singleton")
public class PollingServiceImpl implements PollingService {

      public Response<Map<String, Pojo>> start()  {

         ... implements....
      }

      public void reset()   {

         ... implements....
      }

}


@Service("getDeviceData")
public class DeviceServiceImpl extends RemoteServiceServlet implements
       DeviceService {

   @Autowired
   PollingService pollingService;

   @Override
   public Response<Map<String, Pojo>> getDeviceData() {

          Response<Map<String, Pojo>> result = pollingService.start();
          pollingService.reset();

   }

Szerintem a leírt feladat szempontjából nincs szükség arra, hogy a
"PollingService"-t a Spring kezelje (mivel azt írtad, hogy csak egynek
szabad lennie belőle), a DeviceServiceImpl  nyugodtan lehet akár ilyen
is:

@Service("getDeviceData")
public class DeviceServiceImpl extends RemoteServiceServlet implements
       DeviceService {

   private final PollingServiceImpl pollingService = new PollingServiceImpl();

   @Override
   public Response<Map<String, Pojo>> getDeviceData() {

          Response<Map<String, Pojo>> result = pollingService.start();
           pollingService.reset();

   }


Üdv,
Chico

2012/6/4 zamek <zamek at vili.pmmf.hu>:
> 06/04/2012 07:15 PM keltezéssel, Böszörményi Péter írta:
>
>> Meg lehetne tekinteni, hogy pontosan hogyan nez ki az xml, mik, es hogyan
>> lettek annotalva, milyen csomagokban vannak az osztalyok?
>>
> Persze, csak a relevans reszeket masoltam ki, hogy minel rovidebb legyen. A
> DeviceServiceImpl mukodik, a kliens hivasait tudja fogadni.
>
> applicationContext.xml
> ======================================================
> <?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"
>    xmlns:context="http://www.springframework.org/schema/context"
> xmlns:tx="http://www.springframework.org/schema/tx"
>    xsi:schemaLocation="http://www.springframework.org/schema/beans
>            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>            http://www.springframework.org/schema/context
>
> http://www.springframework.org/schema/context/spring-context-2.5.xsd">
>
> <context:component-scan base-package="com.zamek.monitor.gwt.server"/>
>
> <bean id="getDeviceData"
> class="com.zamek.monitor.gwt.server.device.communication.DeviceServiceImpl"/>
>
>
> </beans>
> ======================================================
>
> web.xml:
> ======================================================
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app 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"
>         version="2.5"
>         xmlns="http://java.sun.com/xml/ns/javaee">
>
> <!-- Servlets -->
> <context-param>
> <param-name>contextConfigLocation</param-name>
> <param-value>/WEB-INF/applicationContext.xml</param-value>
> </context-param>
>
> <listener>
> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
> </listener>
>
> <servlet>
> <servlet-name>springGwtRemoteServiceServlet</servlet-name>
> <servlet-class>org.spring4gwt.server.SpringGwtRemoteServiceServlet</servlet-class>
> </servlet>
>
>
> <servlet-mapping>
> <servlet-name>springGwtRemoteServiceServlet</servlet-name>
> <url-pattern>koszovo/deviceServices/*</url-pattern>
> </servlet-mapping>
>
> <!-- Default page to serve -->
> <welcome-file-list>
> <welcome-file>Koszovo.html</welcome-file>
> </welcome-file-list>
>
> </web-app>
> ======================================================
>
> PollingService.java
> ======================================================
> package com.zamek.monitor.gwt.server;
>
> import javax.annotation.PostConstruct;
>
> import org.springframework.context.annotation.Scope;
> import org.springframework.stereotype.Component;
>
> @Component
> @Scope("singleton")
> public class PollingService {
>
> }
> ======================================================
>
> DeviceServiceImpl.java
> ======================================================
> package com.zamek.monitor.gwt.server.device.communication;
>
> import org.springframework.beans.factory.annotation.Autowired;
> import org.springframework.stereotype.Service;
>
> import com.google.gwt.user.server.rpc.RemoteServiceServlet;
> import com.zamek.monitor.gwt.client.device.communication.DeviceService;
> import com.zamek.monitor.gwt.server.PollingService;
>
>
> @Service("getDeviceData")
> public class DeviceServiceImpl extends RemoteServiceServlet implements
>        DeviceService {
>
>    @Autowired
>    PollingService pollingService;
>
>    @Override
>    public Response<Map<String, Pojo>> getDeviceData() {
>    }
> }
> ======================================================
>
>
> --
>  thx,
> ----------------------------------
> Zoltan Zidarics programmer
> PTE-PMMFK H-7621 Pecs, Boszorkany u. 2. Hungary
> E-Mail: zamek at vili.pmmf.hu
> ----------------------------------
>
> _______________________________________________
> Javalist mailing list
> Javalist at lists.javaforum.hu
> http://lists.javaforum.hu/mailman/listinfo/javalist


További információk a(z) Javalist levelezőlistáról