@Autowired is equivalent to a setter. Before injection, the object has been instantiated, which is instantiated when the interface is annotated;
while new only instantiates an object, and the new object cannot call other injected classes
eg:
1. Controller
@controller
public class BusinessShopShoesController extends BaseController {
@Autowired
private ShoesService shoesService;//equivalent to setter, already instantiated
}
2. Business layer
@service
public class ShoesService extends CrudService<ShoesDao, Shoes> {
@Autowired
ShoesModelDao shoesModelDao;
@Transactional(readOnly = false)
public Shoes get(int id)
{
return shoesModelDao.get(id);
}
}
If there is a new service in 1, then Dao in 2 cannot be called, because DAO is dependency injection
Difference between @Autowired and new
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326337504&siteId=291194637
Ranking