as I integrate 2 spring modules

1

I want to integrate 2 projects that are totally separate but that work in cooperation, and I want to join them in a single project, use a MAVEN multimodule

  

What should I notice? the dependencies? the bookstores?

main class of the first project

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Import;


@SpringBootApplication
@EnableAutoConfiguration
@EnableEurekaClient
@EnableFeignClients
@EnableCircuitBreaker
@Import({
        com.goo.common.notifications.messaging.producer.Application.class
})
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

main class of the second project

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;


@SpringBootApplication
@EnableEurekaClient
public class Application {

    public static void main(String args[])  {
        SpringApplication.run(Application.class, args);
    }
}
    
asked by deluf 05.05.2017 в 18:12
source

2 answers

2

You could use Spring Integration to communicate with each other avoiding dependencies, that means that there is an important principle in the POO under coupling.

It consists of declaring a gateway in the class that invokes the services of another module:

<int:gateway id="gatewayId"
            service-interface="package.nameGateway"
            default-request-channel="requestChannel"
            default-reply-channel="replyChannel" 
            default-reply-timeout="10000">
            <int:method name="method" payload-expression="#args[0]">
                <int:header name="argument1" expression="#args[0]" />
            </int:method>
</int:gateway>

<int:channel id="requestChannel" />

<int:channel id="replyChannel" />

Service activator, declared in the module that listens to the request:

<int:service-activator send-timeout="5000" id="saId" 
            input-channel="requestChannel"
            expression="@nameInterfaceImpl.method(headers.argument1)">
</int:service-activator>

<int:channel id="requestChannel" />
    
answered by 06.05.2017 в 19:26
1

Add:

@ComponentScan(basePackages="<paquete>")
@EntityScan(basePackages="<paquete>")

this would be the change in your main class:

@ComponentScan(basePackages="<paquete>")
@EntityScan(basePackages="<paquete>")
@SpringBootApplication
@EnableAutoConfiguration
@EnableEurekaClient
@EnableFeignClients
@EnableCircuitBreaker
@Import({
        com.goo.common.notifications.messaging.producer.Application.class
})
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
    
answered by 05.05.2017 в 21:33