#190 - More simplifications for Spring Boot 1.4 M3.
Replaced all occurrences of @SpringApplicationConfiguration with @SpringBootTest. Using SpringRunner instead of @SpringJUnit4ClassRunner now.
This commit is contained in:
@@ -21,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import org.thymeleaf.dialect.springdata.SpringDataDialect;
|
||||
|
||||
@@ -36,16 +35,6 @@ public class Application extends WebMvcConfigurerAdapter {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
|
||||
// Configure resource handler explicitly to enable non-versioned
|
||||
// Webjars in Thymeleaf templates
|
||||
registry.addResourceHandler("/webjars/**").//
|
||||
addResourceLocations("classpath:/META-INF/resources/webjars/").//
|
||||
resourceChain(true);
|
||||
}
|
||||
|
||||
@Bean
|
||||
SpringDataDialect springDataDialect() {
|
||||
return new SpringDataDialect();
|
||||
@@ -55,11 +44,6 @@ public class Application extends WebMvcConfigurerAdapter {
|
||||
|
||||
@PostConstruct
|
||||
void initialize() throws Exception {
|
||||
|
||||
// Import demo users from local CSV
|
||||
new UserInitializer(repo).initLocally();
|
||||
|
||||
// Import demo users from remote service
|
||||
// new UserInitializer(repo).initRemote(100);
|
||||
new UserInitializer(repo).init();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,9 +34,7 @@ import org.springframework.batch.item.file.separator.DefaultRecordSeparatorPolic
|
||||
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.util.UriTemplate;
|
||||
|
||||
/**
|
||||
* Initialize {@link UserRepository} with sample data.
|
||||
@@ -47,12 +45,9 @@ import org.springframework.web.util.UriTemplate;
|
||||
@RequiredArgsConstructor
|
||||
public class UserInitializer {
|
||||
|
||||
private static final UriTemplate REMOTE_TEMPLATE = new UriTemplate(
|
||||
"https://randomuser.me/api/?results={numberOfUsers}&format=csv&nat=US");
|
||||
|
||||
private final UserRepository repository;
|
||||
|
||||
public void initLocally() throws Exception {
|
||||
public void init() throws Exception {
|
||||
|
||||
List<User> users = readUsers(new ClassPathResource("randomuser.me.csv"));
|
||||
|
||||
@@ -60,14 +55,6 @@ public class UserInitializer {
|
||||
repository.save(users);
|
||||
}
|
||||
|
||||
public void initRemote(int numberOfUsers) throws Exception {
|
||||
|
||||
List<User> users = readUsers(new UrlResource(REMOTE_TEMPLATE.expand(numberOfUsers)));
|
||||
|
||||
repository.deleteAll();
|
||||
repository.save(users);
|
||||
}
|
||||
|
||||
private static List<User> readUsers(Resource resource) throws Exception {
|
||||
|
||||
Scanner scanner = new Scanner(resource.getInputStream());
|
||||
|
||||
Reference in New Issue
Block a user