I have a java.lang.NullPointerException when I'm trying to insert data in my database.
Here is my configuration Spring and my code:
applicationContext.xml:
 <bean id="myDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
 
    <property name="jndiName" value="jdbc/userDb"/>
     
  </bean>
<bean class="com.example.UserDB" id="user">
        <property name="dataSource" ref="myDataSource"/
UserDB.java:
public class UserAccountLog {
    protected JdbcTemplate jdbcTemplate;
    
    public void setDataSource(DataSource dataSource) {
        jdbcTemplate = new JdbcTemplate(dataSource);
    }
      public void insertNewUser(String username){
        jdbcTemplate.update( connection -> {
            PreparedStatement ps = connection.prepareStatement(sqlUserInsert, new String[]{"id"});
            int i =1;
            ps.setString(i++, username);
        
            return ps;});
    }
}
And I have this error when he tries to do jdbcTemplate.update( connection:
java.lang.NullPointerException
    at com.example.UserDB.insertNewUser
I tried already to make @Autowired annotation in variable Jdbc but not work too,
Please anyone has idea?
 
     
    