J'ai Spring Boot
application que j'initialise comme ceincapable de télécharger le fichier à partir de la page via le repos
@SpringBootApplication
@ComponentScan(basePackages = { "my.high.level.package" })
@EnableEmailTools
@EnableAsync
public class BookViewApplication {
public static void main(String[] args) {
SpringApplication.run(BookViewApplication.class, args);
}
}
ComponentScan
est réglé sur paquet de haut niveau il est donc en mesure de trouver tous les composants (parce que les services, les dépôts etc. fonctionne)
J'ai une config pour afficher la page html
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/books-home").setViewName("forward:/index.html");
}
}
index.html
est bien affiché.
J'ai ServletInitializer
qui ressemble à ceci
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(BookViewApplication.class);
}
}
J'ai spring-data-rest
ressource qui fonctionne très bien
@RepositoryRestResource
public interface IBooksRepository extends CrudRepository<Book, Long> {
}
J'ai un controller
pour le repos
@RestController("/books-rest")
public class BooksWebController {
@Autowired
private IBooksFileRepository fileRepository;
@PostMapping("/upload")
public String uploadFile(@RequestParam("file") MultipartFile file) {
try {
if (!file.isEmpty()) {
fileRepository.writeFile(file.getName(), file.getBytes());
}
} catch (IOException e) {
e.printStackTrace();
}
return "redirect:/books-home";
}
}
Je peux accéder
localhost:8080/books
localhost:8080/books-home
Mais quand je tente d'accéder à la demande POST
localhost:8080/books-rest
en utilisant ce formulaire
<form method="POST" enctype="multipart/form-data" action="/books-rest/upload">
<table>
<tr>
<td>File to upload:</td>
<td><input type="file" name="file" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Upload" /></td>
</tr>
</table>
</form>
je reçois 404 not found
. Quel est le problème?