// src/beans.xml
<beans>
<context:component-scan base-package="com.lijunyang" />
</beans>
// src/com/lijunyang/model/BaseService.java
public class BaseService<T> {
@Autowired
protected BaseRepository<T> repository;
public void add() {
System.out.println("add...");
System.out.println("repository");
}
}
// src/com/lijunyang/model/BaseRepository.java
public class BaseRepository {
}
// src/com/lijunyang/model/User.java
public class User {
}
// src/com/lijunyang/model/UserService.java
@Service
public class UserService extends BaseService<User> {
}
// src/com/lijunyang/model/UserRepository.java
@Repository
public class UserRepository extends BaseRepository<User> {
}
// src/com/lijunyang/test/Main.java
public class Main {
public static main(String args[]) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
UserService userService = (UserService) ctx.getBean("userService");
userService.add();
}
}