0

I am trying to add the ModelMapper dependency via pom.xml, however, when I try create a new instance of modelMapper it doesn't recognize the dependency and instead tries to import modelMapper from Swagger. I have tried adding it manually and still I get the same problem.

XML

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <!-- PARENT --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.4.12</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com</groupId> <artifactId>golden.scent</artifactId> <version>0.0.1-SNAPSHOT</version> <name>something</name> <description>Demo project for Spring Boot</description> <!-- PROPERTIES --> <properties> <java.version>11</java.version> </properties> <!-- DEPENDENCIES --> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency> <!-- https://mvnrepository.com/artifact/org.modelmapper/modelmapper --> <dependency> <groupId>org.modelmapper</groupId> <artifactId>modelmapper</artifactId> <version>2.3.8</version> </dependency> </dependencies> <!-- BUILD --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <excludes> <exclude> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </exclude> </excludes> </configuration> </plugin> </plugins> </build> </project> 

Configuration

import springfox.documentation.swagger2.mappers.ModelMapper; @Configuration public class Config { @Bean public ModelMapper modelMapper(){ return new ModelMapper() } } 

Tried using the invalidate cache/restart which usually solves the problem. not this time.

I am trying to use DTO beans and do not want to write a mapper manually.

I have tried looking for solutions but could not find one yet.

Thanks

2 Answers 2

1

Change your class to the following:

import org.modelmapper.ModelMapper; @Configuration public class Config { @Bean public ModelMapper modelMapper(){ return new ModelMapper(); } } 

If with this you can't compile your code, you might need to delete org/modelmapper folder in the .m2 folder in your machine and reload your maven dependencies again.

Sign up to request clarification or add additional context in comments.

Comments

1

Try nuking your .m2 folder, and then pull dependencies again. I usually do it like this: delete everything from .m/repo, I go to intellij and add space in pom.xml and delete it so it offers me to pull changes that were made in pom.xml

If that does not help, you can always run from your terminal

mvn clean - clear dependencies so you get something like a clean slate

mvn install - initiates the pulling of dependencies again

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.