I am actually working on a sprig boot application. I clone the repository of my project in both ubuntu and macos. The code is working fine in ubuntu but it is not working in macos, I get a compilation Error in mac os which is,
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientTypeController' defined in file [/Users/selvan/Projects/cms/cms-spring/target/classes/ken/advocates/cms/controller/ClientTypeController.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [ken.advocates.cms.controller.ClientTypeController]: Constructor threw exception; nested exception is java.lang.Error: Unresolved compilation problems:
The blank final field clientTypeService may not have been initialized
The method builder() is undefined for the type Response
The method builder() is undefined for the type Response
log cannot be resolved
The method builder() is undefined for the type Response
The method builder() is undefined for the type Response
The method builder() is undefined for the type Response
Please let me know what the problem will be?
I expected the spring boot application to work on both ubuntu and macos. But I get a complier error while building the project in macos. The same code is working fine in Ubuntu
CodePudding user response:
package ken.advocates.cms.controller;
import java.time.LocalDateTime;
import java.util.Map;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.wenter code hereeb.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import ken.advocates.cms.exceptions.ClientTypeNotFoundException;
import ken.advocates.cms.implementation.ClientTypeServiceImpl;
import ken.advocates.cms.model.ClientType;
import ken.advocates.cms.response.Response;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@RestController
@RequiredArgsConstructor
@Slf4j
@Data
public class ClientTypeController {
private final ClientTypeServiceImpl clientTypeService;
@GetMapping("/get/{id}")
ResponseEntity<Response> get(@PathVariable("id") Long id) throws RuntimeException {
return ResponseEntity.ok(Response.builder().timeStamp(LocalDateTime.now())
.data(Map.of("ClientType", clientTypeService.get(id))).message("Client Type retreived by ID: " id)
.status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
}
@GetMapping("/list")
public ResponseEntity<Response> getClientTypes() {
return ResponseEntity.ok(Response.builder().timeStamp(LocalDateTime.now())
.data(Map.of("ClientType", clientTypeService.list(20))).message("Client Types retreived")
.status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
}
@PostMapping("/save")
public ResponseEntity<Response> saveClientType(@RequestBody ClientType clientType) {
log.info("Inside PostMapping /save");
return ResponseEntity.ok(Response.builder().timeStamp(LocalDateTime.now())
.data(Map.of("clientType", clientTypeService.create(clientType))).message("Added a new Client Type.")
.status(HttpStatus.CREATED).statusCode(HttpStatus.CREATED.value()).build());
}
@PutMapping("/update/{id}")
ResponseEntity<Response> update(@RequestBody ClientType newClientType, @PathVariable("id") Long id) {
return ResponseEntity.ok(Response.builder().timeStamp(LocalDateTime.now())
.data(Map.of("ClientType", clientTypeService.update(newClientType, id)))
.message("Client Type retreived by ID: " id).status(HttpStatus.OK).statusCode(HttpStatus.OK.value())
.build());
}
@DeleteMapping("/delete/{id}")
ResponseEntity<Response> delete(@PathVariable("id") Long id) throws RuntimeException {
return ResponseEntity.ok(Response.builder().timeStamp(LocalDateTime.now())
.data(Map.of("ClientType", clientTypeService.delete(id))).message("Client Type deleted by ID: " id)
.status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
}
}
CodePudding user response:
This error message indicates that there are some compilation problems in your code. The specific issues mentioned in the error message are:
- The final field clientTypeService, may not have been initialized.
- The method builder() is undefined for the type Response.
- The variable log cannot be resolved.
Here's what you can do to resolve these issues:
- Check if you have all the necessary dependencies added in your project's pom.xml or build.gradle file.
- Check if the dependencies you added are compatible with your current Java version in MacOS.
- If the dependencies are correct, try to clean and rebuild your project.