vendredi 26 février 2021

Can I annotate classes without data interactions with @Service?

I have a Spring Boot application which does ETL processes and not a web application. I know that the use of services is to separate concerns and provide loose coupling but can I use it with classes that do not deal with the data being processed. I have several classes that I put in my service package and annotated it with @Service such as:

S3Service.java

@Service
public class S3Service {

    @Autowired
    private final AmazonS3 s3Client;

    public File downloadFile(String filename) throws Exception {
        ...
    }

    public File uploadFile(String filename) throws Exception {
        ...
    }

}

FileSecurityService.java

@Service
public FileSecurityService {

    public File decryptFile(String filename) throws Exception {
        ...
    }

    public File encryptFile(String filename) throws Exception {
        ...
    }

}

I did it this way because I think it makes my code cleaner but I don't think this is what services are for. I am hesitant to make them Utility classes because they are a huge part of the process. Is it a bad practice to use @Service this way? If yes, where should I put these? Thank you.

Aucun commentaire:

Enregistrer un commentaire