3 Replies Latest reply on Nov 17, 2016 12:28 PM by richardmoore

    @PostConstruct not firing

    richardmoore

      The postConstruct method is not firing but the preDestroy is. It fails on the first use of the stmt variable because it is initialized in the postConstruct. I do not get the message generated in the postConstruct() but after the NullPointerException on stmt I see the preDestroy message in the log. What do I need to check?

       

      @Named

      public class RPE_Daily_HZMaintenanceDaily extends JdbcItemProcessor {

        private Connection connection;

        private PreparedStatement stmt;

       

        @Override

        public Object processItem(Object input) throws Exception {

          ....

        }

      @PostConstruct

          private void postConstruct() {

      log.info("Creating database resources.");
      try {
      this.connection = this.getConnection();
      this.stmt = this.connection.prepareStatement(SQLString);
      } catch (Exception e) {
      throw new RuntimeException(e);
      }
      }
      @PreDestroy

          private void preDestroy() {

      log.info("Closing database resources.");
      if (this.stmt != null) {
      try {
      this.stmt.close();
      } catch (SQLException e) {
      log.warning(e.getMessage());
      }
      }
      if (this.connection != null) {
      try {
      this.connection.close();
      } catch (SQLException e) {
      log.warning(e.getMessage());
      }
      }
      }