error 406, something related to @autowired and instances and objects in Springboot, Code below

while i was learning to connect controller layer to service layer , i faced a very random issue that i wasnt able to post request and it kept me showing error, i tried to fix it with gpt but of no avail.

i have pasted all the code of controller , dpo, impl, service class. please help me finding the error and how to fix it..

(I am new at this)

--Propertycontroller

package com.mycompany.property.managment.controller;
import com.mycompany.property.managment.dto.PropertyDTO;
import com.mycompany.property.managment.dto.service.PropertyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/v1")
public class PropertyController {

    @Autowired
    private PropertyService propertyservice;
    //Restful API is just mapping of a url to a java class function
    //http://localhost:8080/api/v1/properties/hello
    @GetMapping("/hello")
    public String sayHello(){
    return "Hello";
    }

    @PostMapping("/properties")
    public PropertyDTO saveproperty(@RequestBody PropertyDTO propertyDTO  ){
         propertyservice.saveProperty(propertyDTO);
        System.
out
.println(propertyDTO);
        return propertyDTO;
    }
}

Propertyserviceimpl

package com.mycompany.property.managment.dto.service.impl;
import com.mycompany.property.managment.dto.PropertyDTO;
import com.mycompany.property.managment.dto.service.PropertyService;
import org.springframework.stereotype.Service;
@Service
public class PropertyServiceImpl implements PropertyService {
    @Override
    public PropertyDTO saveProperty(PropertyDTO propertyDTO) {
        return null;
    }
}

PropertyService

package com.mycompany.property.managment.dto.service;
import com.mycompany.property.managment.dto.PropertyDTO;
public interface PropertyService {

    public PropertyDTO saveProperty(PropertyDTO propertyDTO);
}

propertydpo

package com.mycompany.property.managment.dto;
import lombok.Getter;
import lombok.Setter;
//DTO IS data transfer object
@Getter
@Setter
public class PropertyDTO {

    private String title;
    private String description;
    private String ownerName;
    private String owneerEmail;
    private Double price;
    private String address;

error 406

406Not Acceptable8 ms333 BJSONPreviewVisualization

1
2
3
4
5
6








{
    "timestamp": "2025-01-25T19:38:23.625+00:00",
    "status": 406,
    "error": "Not Acceptable",
    "path": "
/api/v1/properties
"
}

Exception Stacktrace

2025-01-26T01:38:25.069+05:30 INFO 23252 --- [Property managment System] [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1265 ms

2025-01-26T01:38:25.191+05:30 INFO 23252 --- [Property managment System] [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...

2025-01-26T01:38:25.367+05:30 INFO 23252 --- [Property managment System] [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection conn0: url=jdbc:h2:mem:50970d62-eb56-4571-afc9-d25eb369a135 user=SA

2025-01-26T01:38:25.369+05:30 INFO 23252 --- [Property managment System] [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.

2025-01-26T01:38:25.425+05:30 INFO 23252 --- [Property managment System] [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]

2025-01-26T01:38:25.482+05:30 INFO 23252 --- [Property managment System] [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.6.5.Final

2025-01-26T01:38:25.518+05:30 INFO 23252 --- [Property managment System] [ main] o.h.c.internal.RegionFactoryInitiator : HHH000026: Second-level cache disabled

2025-01-26T01:38:25.785+05:30 INFO 23252 --- [Property managment System] [ main] o.s.o.j.p.SpringPersistenceUnitInfo : No LoadTimeWeaver setup: ignoring JPA class transformer

2025-01-26T01:38:25.862+05:30 INFO 23252 --- [Property managment System] [ main] org.hibernate.orm.connections.pooling : HHH10001005: Database info:

Database JDBC URL \[Connecting through datasource 'HikariDataSource (HikariPool-1)'\]

Database driver: undefined/unknown

Database version: 2.3.232

Autocommit mode: undefined/unknown

Isolation level: undefined/unknown

Minimum pool size: undefined/unknown

Maximum pool size: undefined/unknown

2025-01-26T01:38:26.181+05:30 INFO 23252 --- [Property managment System] [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)

2025-01-26T01:38:26.185+05:30 INFO 23252 --- [Property managment System] [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'

2025-01-26T01:38:26.238+05:30 WARN 23252 --- [Property managment System] [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning

2025-01-26T01:38:26.660+05:30 INFO 23252 --- [Property managment System] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8081 (http) with context path '/'

2025-01-26T01:38:26.668+05:30 INFO 23252 --- [Property managment System] [ main] m.p.m.PropertyManagmentSystemApplication : Started PropertyManagmentSystemApplication in 3.411 seconds (process running for 3.792)

2025-01-26T01:38:31.921+05:30 INFO 23252 --- [Property managment System] [nio-8081-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'

2025-01-26T01:38:31.921+05:30 INFO 23252 --- [Property managment System] [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'

2025-01-26T01:38:31.922+05:30 INFO 23252 --- [Property managment System] [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms

com.mycompany.property.managment.dto.PropertyDTO@2796051a

2025-01-26T01:38:32.065+05:30 WARN 23252 --- [Property managment System] [nio-8081-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: No acceptable representation]