简体   繁体   中英

Not able to inject Person service as autowired

I'm trying to use person service as part of spring application.

Here is my code

@Entity
@Table(name="person_data")
class Person {

@Id
    @Column(
    columnDefinition = "NUMERIC(19,0)"
)
private Long id;
private String first_name;
private String last_name;

public String getFullName() {
    return new StringBuilder().append(first_name).append(last_name).toString();
}
}

@Service
class PersonService {

@Autowired 
PersonRepository repository;

List<Person> findAll() {
    return (List<Person>) repository.findAll();
}

}


@Repository
interface PersonRepository extends CrudRepository<Person, Long> {}

When I build the above the code, I'm getting the following exception

 ERROR] /task/src/main/java/com/codility/tasks/hibernate/solution/Solution.java:[36,6] can  
 not find symbol
 symbol:   class Autowired
 location: class com.codility.tasks.hibernate.solution.PersonService
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.451 s
[INFO] Finished at: 2020-09-09T06:40:46Z
[INFO] ------------------------------------------------------------------------
   [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile 
   (default-compile) on project hibernate-one-to-many-task: 
Compilation failure
[ERROR] 

Why is it not able to autowire

Import statement was missing. Thank you all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM