0

I am having issue when I deploy the jar in AWS ubuntu server,I have 2 packages in Spring Boot.

#1)core package

#2)Process package

The first package(core) is not containing spring boot dependency and generate the jar using maven package,When I run the code the below code works fine in Intellij. But when I deploy in AWS Ubuntu machine I get Null Pointer Exception for MySQLAdapter Class used in the Process PackageController. Below is the code

//Code in Process

 @SpringBootApplication
 public class ProcessApplication
 {
   @Bean
   MySQLAdapter mySQLAdapter() {
   MySQLAdapter mySQLAdapter = new MySQLAdapter();
    return mySQLAdapter;
   }
   
   public static void main(String[] args) {
     SpringApplication.run(com.test.ProcessApplication.class, args);
   }
 }

// Core package jar

 public class MySQLAdapter {
      private String hostName;
      private int port;
      private String DBName;
      private String username;
      private String pwd;
      private String secretPwdKey;
      private com.test.Util.CryptoUtil cryptoUtil;
    
    
      public MySQLAdapter() {
        hostName = "localhost";
        port = 3306;
        username = "test";
        pwd = "test";
        DBName = "test";
        secretPwdKey = "test";
        cryptoUtil = new com.test.Util.CryptoUtil();
      }
    }

Is this Null Pointer Exception because of cryptoUtil not getting injected or instantiated? How can this be solved?

// Controller inside Process package 
@RestController
class MyRestController{
@Autowired
MySQLAdapter mySQLAdapter;

     @RequestMapping(value = {"/register"}, method = {RequestMethod.POST}, produces = {"application/json"})
   @ResponseBody
   public RegistrationResponse register(@Valid @RequestBody UserPojo userPojo) {

  if (!this.mySQLAdapter.checkClientID(userPojo.getClientID())) { //Null Pointer thrown here


   }
  }
}
SSSS
  • 33
  • 1
  • 6
  • Does this answer your question? [Why is my Spring @Autowired field null?](https://stackoverflow.com/questions/19896870/why-is-my-spring-autowired-field-null) – Karthikeyan Mar 30 '22 at 05:51

0 Answers0