2

I am new with spring boot, is very simple my question but I can´t find where is the problem.

I have a basic @GetMapping and @DeleteMapping

@RestController
    public class MyController
    {
       private MyServiceImpl myService;

       @Autowired
       public MyController(MyServiceImpl myService)
       {
          this.myService = myService;
       }

       @GetMapping("/test")
       public List<Scan>  getTestData(@RequestParam(value = "test_id", required = true) String test_id) {
          return myService.findByTestId( test_id );
       }

      @DeleteMapping("/test")
       public int deleteData(@RequestParam(value = "test_id", required = true) String test_id){
          return myService.deleteTest( test_id );
       }

 @DeleteMapping("/test2")
   public String deleteArticle() {
      return "Test";
   }

    }

I am testing with Postman, the Get request is working, but the delete request is not. Even when I debug the spring boot application. The GetMapping is called, whereas the delete is not "reacting" /called

Maybe is not enough information, but I even tested @DeleteMapping("/test2") is not doing anything, I mean, I get no response, and in Postman it stays "loading..."

Any suggestions?

My complete POM

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<parent>
    <groupId>com.ttt.pdt</groupId>
    <artifactId>pdt-base</artifactId>
    <version>2.0-SNAPSHOT</version>
</parent>

<artifactId>pdt-service</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </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.4.0</version>
    </dependency>

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.4.0</version>
    </dependency>

</dependencies>
<build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

The parent (pdt-base) has

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
</parent>

test_no is equivalent to test_id

MyServiceImpl

@Service
public class MyServiceImpl
{
   private ScnDao scnDao;

   @Autowired
   public ScanServiceImpl(ScnDao scnDao){
      this.scnDao = scnDao;
   }

   public int deleteTest( String test_id )
   {
      return scnDao.deleteTest( test_id );
   }

}

public interface ScanDao
{

   int deleteTest( String test_id )
}

@Repository
    public class ScnPostgres implements ScnDao
    {

       private JdbcTemplate jdbcTemplate;

       @Autowired
       public ScnPostgres( JdbcTemplate jdbcTemplate )
       {
          this.jdbcTemplate = jdbcTemplate;
       }

       public int deleteTest( String test_id )
        {
            String SQL = "DELETE FROM scn WHERE test_id = ?";
            return jdbcTemplate.update( SQL, new String[] { test_id } );
        }

    }
marhg
  • 659
  • 1
  • 17
  • 30
  • what spring boot version are you using? Can you show the whole pom? – Boris Zhguchev Aug 10 '18 at 09:59
  • 1
    @БорисЖгучев I just added the pom – marhg Aug 10 '18 at 10:28
  • what do you mean `not doing anything`? do you get **any** response? maybe error or something? What's in the response section in Postman? – Debanik Dawn Aug 10 '18 at 10:35
  • @DebanikDawn I just uploaded the postman image, is just keeps "loading..." and I there is no "reaction" in spring boot – marhg Aug 10 '18 at 10:40
  • First your code wouldn't even compile as in your controller you use `test_id` which suddenly becomes `parcel_no`. Your parameter named `test_id` doesn't match the name `test_no` you are using in postman. Please put some proper code and request in here, currently there is a mismatch. – M. Deinum Aug 10 '18 at 10:50
  • I'm not sure about this, but maybe there's a problem because you have **both** a GET and a DELETE mapping for `/test`? Try to change the mapping for delete to `test_delete` or something and tell me. – Debanik Dawn Aug 10 '18 at 10:51
  • @M.Deinum updated – marhg Aug 10 '18 at 10:53
  • Your controller are wating for "test_id" and you send "test_no" .Can you change this var name? and what do your MyServiceImpl do with data? can you show or describe it? – Boris Zhguchev Aug 10 '18 at 11:16
  • can you show whole class where deleteArticle() is defined? – luboskrnac Aug 10 '18 at 11:35
  • @luboskrnac I just added the deleteArticle method – marhg Aug 10 '18 at 11:53
  • @БорисЖгучев I just added – marhg Aug 10 '18 at 12:17
  • is MyServiceImpl been compiling? Cool. :). Try to change ```jdbcTemplate.update( SQL, new String[] { test_id } )``` to ```jdbcTemplate.update( SQL, test_id )```, because i don't see method update with that characters - [api](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/core/JdbcTemplate.html#update-java.lang.String-java.lang.Object...-) – Boris Zhguchev Aug 10 '18 at 12:47
  • @Борис Жгучев Actually it worked when I deleted the RequestParam (@RequestParam(value = "test_id", required = true) and leave it just as deleteData(). But my question is ... in DeleteMapping, is not allowed to have RequestParam?? – marhg Aug 10 '18 at 12:53
  • yep. you are right. My answer below. – Boris Zhguchev Aug 10 '18 at 13:08

1 Answers1

1

As in SPR comments described SPR-16874:

it does not support DELETE currently. It would be a trivial change to make. There is suggested a workaround:

@DeleteMapping(value = "/greeting")
public Greeting handle(@RequestBody MultiValueMap<String, String> params) {
    return new Greeting(counter.incrementAndGet(),
                        String.format(template, params));
}

As you can see the issue has been opened in the spring boot tracker.

Boris Zhguchev
  • 313
  • 4
  • 12