upgrade bootstrap project

This commit is contained in:
Loredana Crusoveanu
2018-05-08 22:04:21 +03:00
parent 88a3f6c0fe
commit 08c0b590b0
6 changed files with 34 additions and 19 deletions
@@ -0,0 +1,20 @@
package org.baeldung.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest()
.permitAll()
.and().csrf().disable();
}
}
@@ -8,5 +8,4 @@ import java.util.Optional;
public interface BookRepository extends CrudRepository<Book, Long> {
List<Book> findByTitle(String title);
Optional<Book> findOne(long id);
}
@@ -6,6 +6,7 @@ import org.baeldung.web.exception.BookIdMismatchException;
import org.baeldung.web.exception.BookNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@@ -37,21 +38,22 @@ public class BookController {
@GetMapping("/{id}")
public Book findOne(@PathVariable long id) {
return bookRepository.findOne(id)
return bookRepository.findById(id)
.orElseThrow(BookNotFoundException::new);
}
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public Book create(@RequestBody Book book) {
return bookRepository.save(book);
Book book1 = bookRepository.save(book);
return book1;
}
@DeleteMapping("/{id}")
public void delete(@PathVariable long id) {
bookRepository.findOne(id)
bookRepository.findById(id)
.orElseThrow(BookNotFoundException::new);
bookRepository.delete(id);
bookRepository.deleteById(id);
}
@PutMapping("/{id}")
@@ -59,7 +61,7 @@ public class BookController {
if (book.getId() != id) {
throw new BookIdMismatchException();
}
bookRepository.findOne(id)
bookRepository.findById(id)
.orElseThrow(BookNotFoundException::new);
return bookRepository.save(book);
}
@@ -7,10 +7,8 @@ spring.thymeleaf.enabled=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
security.basic.enabled=true
security.user.name=john
security.user.password=123
spring.security.user.name=john
spring.security.user.password=123
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:bootapp;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE