Manual configuration of Spring Data

3

I'm trying to use SpringData in a JFace / SWT project. Because the CrudRepository auto-deployment feature is fantastic and very advantageous.

For this, I include here in the classpath the necessary SpringData things: Spring Data Commons, Spring Data JPA, Spring Bean, Spring Context.

For me, it would be only 4 steps to do this manually:

1 - Include the jars in the classpath (I have no classpath error) 2 - Note in the application the information for the Spring to leave the classes cassandos:

@Configuration
@ComponentScan(basePackages = "org.wender.foobar")
public class ControleGadoApp extends ApplicationWindow {

3 - Create an interface that extends the CrudRepository:

public interface ClientRepository extends CrudRepository

4 - Create a class attribute and annotate it with @Autowired

public class TelaCliente extends AbstractTela {

    @Autowired
        private ClienteRepository repository;

These four steps were not enough, @Autowired did not work and the class variable is coming null.

Are there any other settings?

    
asked by anonymous 15.10.2017 / 14:19

1 answer

2

The problem is that the application was not being initialized as a Spring application. For me this was not necessary for desktop application, it was a web application thing. (1) annotate @SpringBootApplication and (2) implement CommandLineRunner

@SpringBootApplication
public class App extends ApplicationWindow implements CommandLineRunner  {

@Override
public void run(String... args) throws Exception {
   //Aqui eu coloquei o que antes estava no método main 
}

public static void main(String args[]) {
    SpringApplication.run(App.class, args);
}
    
18.10.2017 / 14:03