Search Posts

Category: spring-boot

Spring Boot + Angular2 App – How to show index.html for specified routes?

I have developed a Spring Boot application that has @RestController for web api resources. I’m serving the front-end Angular2 website from the same Spring Boot application. Some of the url routes are in the Angular2 app. For example, currently when the url http://localhost:8080/myapp is typed in the browser, it shows the index.html page from Angular2 app. Within this page there’s more routing. Eg: http://localhost:8080/myapp/route1 http://localhost:8080/myapp/route2 These are working fine as long as I go to […]

Spring Boot shows the String instead of the HTML file from an Angular2 Single Page app

I’m trying to map all GET requests to unmapped url of the site to show the index.html file. So, I created the following @RestController: @RequestMapping(method=RequestMethod.GET) public String redirectToIndex() { return “index.html”; } My index.html is in resources/static/index.html. I also tried the following controller: @RequestMapping(method=RequestMethod.GET) public String redirectToIndex() { return “/static/index.html”; } However, in both cases, browser literally shows the strings index.html and /static/index.html respectively instead of showing the html file. I tried a lot of […]

Null pointer exception while trying to upload a CSV file to the server

I am trying to upload a csv file to the server. Below is my code in html: <form method=”post” id=”uploadCSV” enctype=”multipart/form-data”> File to upload: <input type=”file” id=”uploadfile” name=”file” accept=”text/csv”> <input type=”submit” value=”Upload” id=”uploadcsv” ng-click=”uploadCSV()”> Press here to upload the file! </form> And my JS:- $scope.uploadCSV = function() { var fileToLoad = document.getElementById(“uploadfile”).files[0]; var csvreporturl = “/api/oel/csv”; $, fileToLoad).then(function(response, status) { console.log(“posted:”,response); }); } Finally the controller in Spring Boot:- @RequestMapping(value = “/api/oel/csv”, method = RequestMethod.POST) […]

Spring Boot ngRoute

I’m trying to make a single page application with a Spring back end and an AngularJS front end. I’ve followed tutorials and looked up similar questions but ngRoute just doesn’t seem to work with a Spring back end (I got it to work with a NodeJS back end). index.html <!DOCTYPE html> <html lang=”en”> <head> <meta charset=”UTF-8″/> <title>Spring Demo</title> <script src=””></script> <script src=””></script> <script src=”../static/index.js”></script> </head> <body ng-app=”index” ng-controller=”indexController”> <a href=”/test”>test</a> <div ng-view=””></div> </body> </html> test.html […]

GET angular.js files net::ERR_ABORTED

I need your help to find out where’s my error. I am using springboot(backend) x Angularjs(frontend). I get a GET (angular.js) files net::ERR_ABORTED when trying to load localhost:8080. I don’t find any mistake on my angularfiles either. So here is my codes: //for the springcontroller @RestController public class EmployeeController { @Autowired EmployeeService es; @RequestMapping(method=RequestMethod.GET,value=”/employees”) public List<Employee> getAllEmployees(){ return es.getAllEmployees(); } @RequestMapping(method=RequestMethod.GET,value=”/employees/{name}”) public Employee getEmployee(@PathVariable String name){ return es.getEmployee(name); } @RequestMapping(method=RequestMethod.POST,value=”/employees”) public void addEmployee(@RequestBody Employee emp){ […]

Required request part ‘file’ is not present

Hello guys I’m trying to build a file upload application using AngularJs but I.m getting this error Required request part ‘file’ is not present here is my code help me upload.html <!DOCTYPE html> <html xmlns:th=””> <body> <h1>Spring Boot File Upload Using REST</h1> <div ng-app=’app’> <div ng-controller=’myctrl’> <form method=”POST” enctype=”multipart/form-data” id=”fileUploadForm”> <input type=”file” id=”file1″ name=”file” ng-files=”getTheFiles($files)” /> <input type=”button” ng-click=”uploadFiles()” value=”Upload” /> </form> <h1> Result</h1> <pre> <span id=”result”></span> </pre> </div> </div> <script src=””> </script> <script type=”text/javascript” […]

Spring boot CORS Filter not working with AngularJS

I have created a SpringBoot application which has an AngularJS front-end and I am not using any Spring Security modules. I have added the @CrossOrigin annotation in my controller as follows @CrossOrigin(origins = “http://localhost:3000”, maxAge = 3600) @RestController public class MyController { public static final Logger logger = LoggerFactory.getLogger(MyController.class); ….. ….. I have also created a CORS filter as shown below. @Component public class CORSFilter implements Filter { public void doFilter(ServletRequest req, ServletResponse res, FilterChain […]

Jhipster-generator error on production profile

I’m Trying to run my app in production profile, i’m using jhipster-generator for spring-boot app and angular. The app only run the footer and the background but the rest of the aplication nope, The error Uncaught Error: [$injector:modulerr] Failed to instantiate module myAppdue to: Error: [$injector:nomod] Module ‘myApp’ is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second […]

Convert ByteArray into Image in AngularJs

I have written a controller in spring boot for getting image of particular user and i am returning it in form of byte array @GetMapping(value = “/images/{id}/{login}”,produces = {MediaType.APPLICATION_OCTET_STREAM_VALUE}) public byte[] getImage(@Valid @RequestParam(“id”) String id,@RequestParam(“login”) String login) throws IOException, XmlPullParserException, NoSuchAlgorithmException, InvalidKeyException, InvalidArgumentException, ErrorResponseException, NoResponseException, InvalidBucketNameException, InsufficientDataException, InternalException { return IOUtils.toByteArray(fileService.getImage(id, login)); } Is there a method in angularjs so that i could convert it in form of image So that i could display the […]

Next Page »