CrudRepository & Autowire

Hi - I created a repository interface:

public interface IUserRepository extends CrudRepository<User, Long>
{
// Note
// -----
// That we can declare findByXXX() methods (XXX is the name of a field in the domain model class),
// and Spring Data JPA will generate the appropriate code:

Optional<User> findByGid(String gid);

Optional<User> findByUsername(String username);

}

I can get that autowired in my UserDetailServices - no issues

@Service
public class UserDetailsServiceImpl implements UserDetailsService
{
@Autowired
private IUserRepository userRepository;

}

@Autowired - doesn’t work in my Vaadin views

PageTitle(“Home”)
@Route(value = “home”, layout = MainLayout.class)
@RouteAlias(value = “”, layout = MainLayout.class)
@PermitAll
public class HomeView extends TapestryRouterViewSkeleton
{
// @Autowired
private IUserRepository userRepository;

}

It is always null.

Nay help would be appreciated.

When is it null? It’s RECOMMENDED to use constructor injection and NOT field injection.

Thanks knoobie! Just did tried that, works like I need!