I have Swing application with Spring Boot and Spring Data JPA and without beans.xml (I use just annotations). So started normally. I used next annotations:
@SpringBootApplication
@ComponentScan("com.customerproject")
@EnableAutoConfiguration
public class Application { ... }
1.I have repository interface:
@Repository("profileRepository")
public interface ProfileRepository extends CrudRepository<Profile, Long> {}
2.In main application class (Application) some method I declared with annotation @Bean - here I returned new instance of main frame (MainFrame) - work correctly, It's OK:
...// annotations
public class Application {
// ... method main, DataSource and other methods
@Bean
public MainFrame frame() { return new MainFrame(); }
}
So, started application - showing MainFrame window.
3.In MainFrame I call new frame (CreateProfileFrame) like:
CreateProfileFrame cpf = new CreateProfileFrame();
cpf.setVisible(true);
In 'CreateProfileFrame' I declared my repository:
@Autowired
private ProfileRepository profileRepository;
And have method for data manipulation - creating Profile from repository:
Profile pr = new Profile();
pr.setEmail(emailTextField.getText());
Profile saved = profileRepository.save(profile);
But have NullPointerException in last line from this code: profileRepository.save(profile); bacause profileRepository is null.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
So question... - how can I use repository with @Autowired annotation anywhere in different classes or frames? Help, please.