2
In the development of a Spring Boot application for Desktop, it is possible to inject a @Repository
in a class JFrame
?
If yes how? Some alternative?
Code examples:
@Repository
public interface ItemRepository extends CrudRepository<Item, Long> {}
public class ItemFrame extends JFrame {
@Autowired
private ItemRepository repository;
}
That code gives NullPointerException
, I tried to write down the class with @Component
and @Controller
but successful.
Below 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);
}
}
For the autowired to work the class has to be instantiated by Spring. Where the Itemframe class is being instantiated in its code?
– Sérgio Mucciaccia
I am manually instantiating in the main class, as I edited the question.
– Shura16