When developing a Spring Boot Desktop application, can you inject a @Repository
into a JFrame
class?
If yes how? Any alternative?
Code samples:
@Repository
public interface ItemRepository extends CrudRepository<Item, Long> {}
public class ItemFrame extends JFrame {
@Autowired
private ItemRepository repository;
}
This code gives NullPointerException
, I already tried to annotate the class with @Component
and @Controller
but on success.
Here is an example of the main class.
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class);
new ItemFrame().setVisible(true);
}
}