Problem with Spring Boot Mapping

Asked

Viewed 64 times

0

Hello, I have the following project structure using Spring Boot and I’m having problems es create their Beans:

project1: com.portal (spring-boot service)

contem os @Controllers

project2: with.service

contem os @Service e @Component

project3: with.model

contem os @Repository

The portal project does not talk to the model only with the service, which in turn talks to the model.

But when it comes to raising the service of the project1 with.portal, it gives an error saying that it cannot access a class of the project with.model, which I believe is correct because the portal does not have access to the classes of the model.

Is there any way around this in spring boot or am I doing the wrong project structure?

  • in my view the structure is "correct", but you should not return the model, but rather a

  • hi @Lucasmiranda is exactly what I do, always return a DTO, but even so spring is complaining, I realized that this occurred due to the deletion of a package, because I put the model as dependency service, and when I put the service as dependency of the portal I delete the package of the model, from there it starts to give error, if I shoot the exclusion works

1 answer

1

The problem was, because when injecting the service package into the portal design, we were excluded the model package, because it is injected into the service and I do not want the portal to see the model, causing spring not to find the model classes.

<dependencies>
    <dependency>
        <groupId>service</groupId>
        <artifactId>service</artifactId>
        <version>1.0</version>
        <exclusions>
            <exclusion>
                <groupId>model</groupId>
                <artifactId>model</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

the solution was to delete the package from the model in the above way and add in scopo at runtime so when the system runs spring can find the classes

<dependencies>
    <dependency>
        <groupId>com.officersoft.basic-service</groupId>
        <artifactId>basic-service</artifactId>
        <version>1.0</version>
        <exclusions>
            <exclusion>
                <groupId>com.officersoft.basic-model</groupId>
                <artifactId>basic-model</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.officersoft.basic-model</groupId>
        <artifactId>basic-model</artifactId>
        <version>1.0</version>
        <scope>runtime</scope>
    </dependency>
</dependencies>

I don’t know if that’s the best solution, but that’s what we found.

If anyone has any idea how to do it differently, feel free to comment.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.