nullpointerexception while autowire

Solutions on MaxInterview for nullpointerexception while autowire by the best coders in the world

showing results for - "nullpointerexception while autowire"
Farah
07 Jan 2018
1@Controller
2public class Controller {
3
4  @GetMapping("/example")
5  public String example() {
6    MyService my = new MyService();
7    my.doStuff();
8  }
9}
10
11@Service
12public class MyService() {
13
14  @Autowired
15  MyRepository repo;
16
17  public void doStuff() {
18    repo.findByName( "steve" );
19  }
20}
21
22 
23
24@Repository
25public interface MyRepository extends CrudRepository<My, Long> {
26
27  List<My> findByName( String name );
28}
29
Valeria
08 Apr 2018
1@Controller
2public class Controller {
3
4  @Autowired
5  MyService service;
6
7  @GetMapping("/example")
8  public String example() {
9    service.doStuff();
10  }
11}
12
13@Service
14public class MyService() {
15
16  @Autowired
17  MyRepository repo;
18
19  public void doStuff() {
20    repo.findByName( "steve" );
21  }
22}
23
24@Repository
25public interface MyRepository extends CrudRepository<My, Long> {
26
27  List<My> findByName( String name );
28}
29
similar questions
laravellivewire is not definedcould not autowire no beans of type foundfragment button nullpointerexceptionjava lang nullpointerexception 3a attempt to invoke virtual method 27void android widget textview settext 28java lang charsequence 29 27 on a null object referencea livewire component was not foundnot works in customexceptionhandler because in defaulthandlerexceptionresolverautoreconf 3a automake failed with exit status 3a 1 gpaste errorjava lang nullpointerexception 3a attempt to invoke virtual method 27long java lang long longvalue 28 29 27 on a null object referencenullpointerexception javagetcontext canvas not autocompleteattribute 5blivewire 5d does not exist cannot read property 27autoplayhoverpause 27 of nulllivewire wire loading remove attributenullpointerexceptionnullinjectorerror 3a no provider for httphandler 21spring environment null pointer exceptionautomapper c 23 initialize errorlivewire not workingcould not autowire no beans of type found in springbootapplicationeureka exception encountered during context initializationcannot autowire argument 24manager of 22app 5ccontroller 5cadcontroller 3a 3acreate 28 29 22 3a it references interface 22doctrine 5ccommon 5cpersistence 5cobjectmanager 22 but no such service exists did you create a class that implements this interface 3fdisable livewire error modellaravel livewire livewire js 404 not foundnullinjectorerror 3a no provider for activatedrouteerror inflating class android support constraint constraintlayoutnullpointerexceptionid int not null auto increment