본문 바로가기

카테고리 없음

opendaylight blueprint 적용(annotation)

opendaylight 프로젝트에서 blueprint 사용시 xml 을 통해 설정하기 매번 귀찮을때가 있습니다. 

그럴땐 어노테이션을 사용하면 Spring에서 개발하던 방법으로 손쉽게 개발이 가능 합니다. 
 pom.xml 수정 
 dependency 수정
<dependency>

<groupId>org.opendaylight.infrautils</groupId>

<artifactId>inject</artifactId>

<version>1.1.2-Carbon</version>

</dependency>

<dependency>

<groupId>javax.inject</groupId>

<artifactId>javax.inject</artifactId>

<optional>true</optional>

</dependency>

<dependency>

<groupId>org.ops4j.pax.cdi</groupId>

<artifactId>pax-cdi-api</artifactId>

<optional>true</optional>

</dependency>

plugin 추가

<plugin>

                <groupId>org.apache.aries.blueprint</groupId>

                <artifactId>blueprint-maven-plugin</artifactId>

                <version>1.6.0</version>

                <executions>

                    <execution>

                        <goals>

                            <goal>blueprint-generate</goal>

                        </goals>

                    </execution>

                </executions>

                <configuration>

                    <scanPaths>

            <scanPath>패키지경로</scanPath>

        </scanPaths>

                </configuration>

            </plugin>

어노테이션 적용 코드
@Singleton
@OsgiServiceProvider
public class TestProvider {

	private NotificationProviderService notificationService;
	private DataBroker dataBroker;	
	private BindingAwareBroker bindingAwareBroker;
	
	@Inject
	private InitDataSync initDataSync;

	@Inject
	public TestProvider (@OsgiService BindingAwareBroker bindingAwareBroker, 
@OsgiService DataBroker dataBroker, @OsgiService NotificationProviderService notificationService) { this.bindingAwareBroker = bindingAwareBroker; this.dataBroker = dataBroker; this.notificationService = notificationService; } @PostConstruct public void init() { LOG.info("Initiated"); } @PreDestroy public void close() throws Exception { LOG.info("Closed"); } } @Singleton public class InitDataSync implements DataSync{ }