BaseService:有RoleService和UserService两的子类
BaseRepepositry:有UserRepository和RoleRepositry两个子类
由于BaseService和BaseRepepositry有关系所以,得出下面的子类也存在这样的关系
具体代码
1、User.java
package com.proc.bean;
public class User {
}
2、BaseRepository.java
package com.proc.repository;
public class BaseRepository {
}
3、BaseService.java
package com.proc.service;
import org.springframework.beans.factory.annotation.Autowired;
import com.proc.repository.BaseRepository;
public class BaseService {
@Autowired
protected BaseRepository baseRepository;
public void save(){
System.out.println("save ………………");
System.out.println(baseRepository);
}
}
4、UserRepository.java
package com.proc.repository;
import org.springframework.stereotype.Repository;
import com.proc.bean.User;
@Repository
public class UserRepository extends BaseRepository {
}
5、UserService.java
package com.proc.service;
import org.springframework.stereotype.Service;
import com.proc.bean.User;
@Service
public class UserService extends BaseService{
}
6、xml配置
7、代码测试
ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
UserService userService=(UserService) ctx.getBean("userService");
userService.save();
输出结果:
save ………………
com.proc.repository.UserRepository@15bfd87
这里可以看到对象的类型为UserRepository
https://www.cnblogs.com/caoyc/category/844644.html