Skip to content

Commit fe122a2

Browse files
authored
Merge pull request eugenp#4202 from eugenp/spring-boot-2-upgrade
upgrade bootstrap project
2 parents e78a492 + 008054a commit fe122a2

6 files changed

Lines changed: 31 additions & 19 deletions

File tree

‎spring-boot-bootstrap/pom.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
<description>Demo project for Spring Boot</description>
1010

1111
<parent>
12-
<artifactId>parent-boot-5</artifactId>
12+
<artifactId>parent-boot-2</artifactId>
1313
<groupId>com.baeldung</groupId>
1414
<version>0.0.1-SNAPSHOT</version>
15-
<relativePath>../parent-boot-5</relativePath>
15+
<relativePath>../parent-boot-2</relativePath>
1616
</parent>
1717

1818
<!-- add dependency management if you have a different parent pom
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.baeldung.config;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
5+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
6+
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
7+
8+
@Configuration
9+
@EnableWebSecurity
10+
public class SecurityConfig extends WebSecurityConfigurerAdapter {
11+
12+
@Override
13+
protected void configure(HttpSecurity http) throws Exception {
14+
http.authorizeRequests()
15+
.anyRequest()
16+
.permitAll()
17+
.and().csrf().disable();
18+
}
19+
20+
}

‎spring-boot-bootstrap/src/main/java/org/baeldung/persistence/repo/BookRepository.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@
88

99
public interface BookRepository extends CrudRepository<Book, Long> {
1010
List<Book> findByTitle(String title);
11-
Optional<Book> findOne(long id);
1211
}

‎spring-boot-bootstrap/src/main/java/org/baeldung/web/BookController.java‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.baeldung.web.exception.BookNotFoundException;
77
import org.springframework.beans.factory.annotation.Autowired;
88
import org.springframework.http.HttpStatus;
9+
import org.springframework.web.bind.annotation.CrossOrigin;
910
import org.springframework.web.bind.annotation.DeleteMapping;
1011
import org.springframework.web.bind.annotation.GetMapping;
1112
import org.springframework.web.bind.annotation.PathVariable;
@@ -37,29 +38,30 @@ public List<Book> findByTitle(@PathVariable String bookTitle) {
3738

3839
@GetMapping("/{id}")
3940
public Book findOne(@PathVariable long id) {
40-
return bookRepository.findOne(id)
41+
return bookRepository.findById(id)
4142
.orElseThrow(BookNotFoundException::new);
4243
}
4344

4445
@PostMapping
4546
@ResponseStatus(HttpStatus.CREATED)
4647
public Book create(@RequestBody Book book) {
47-
return bookRepository.save(book);
48+
Book book1 = bookRepository.save(book);
49+
return book1;
4850
}
4951

5052
@DeleteMapping("/{id}")
5153
public void delete(@PathVariable long id) {
52-
bookRepository.findOne(id)
54+
bookRepository.findById(id)
5355
.orElseThrow(BookNotFoundException::new);
54-
bookRepository.delete(id);
56+
bookRepository.deleteById(id);
5557
}
5658

5759
@PutMapping("/{id}")
5860
public Book updateBook(@RequestBody Book book, @PathVariable long id) {
5961
if (book.getId() != id) {
6062
throw new BookIdMismatchException();
6163
}
62-
bookRepository.findOne(id)
64+
bookRepository.findById(id)
6365
.orElseThrow(BookNotFoundException::new);
6466
return bookRepository.save(book);
6567
}

‎spring-boot-bootstrap/src/main/resources/application.properties‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ spring.thymeleaf.enabled=true
77
spring.thymeleaf.prefix=classpath:/templates/
88
spring.thymeleaf.suffix=.html
99

10-
security.basic.enabled=true
11-
security.user.name=john
12-
security.user.password=123
13-
10+
spring.security.user.name=john
11+
spring.security.user.password=123
1412

1513
spring.datasource.driver-class-name=org.h2.Driver
1614
spring.datasource.url=jdbc:h2:mem:bootapp;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE

‎spring-boot-bootstrap/src/test/java/org/baeldung/SpringBootBootstrapIntegrationTest.java‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.baeldung;
22

3-
import static io.restassured.RestAssured.preemptive;
43
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
54
import static org.apache.commons.lang3.RandomStringUtils.randomNumeric;
65
import static org.junit.Assert.assertEquals;
@@ -11,7 +10,6 @@
1110
import java.util.List;
1211

1312
import org.baeldung.persistence.model.Book;
14-
import org.junit.Before;
1513
import org.junit.Test;
1614
import org.junit.runner.RunWith;
1715
import org.springframework.boot.test.context.SpringBootTest;
@@ -24,11 +22,6 @@
2422
@SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.DEFINED_PORT)
2523
public class SpringBootBootstrapIntegrationTest {
2624

27-
@Before
28-
public void setUp() {
29-
RestAssured.authentication = preemptive().basic("john", "123");
30-
}
31-
3225
private static final String API_ROOT = "http://localhost:8081/api/books";
3326

3427
@Test

0 commit comments

Comments
 (0)