Pessoal, estou tendo problema no seguinte código. Acho que o eclipse não está importando o Autowired nem o Qualifier.
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
//import com.journaldev.spring.model.Person;
//import com.journaldev.spring.service.PersonService;
@Controller
public class CompanyController {
private CompanyService companyService;
@Autowired(required=true)
@Qualifier(value="companyService")
public void setCompanyService(CompanyService cs){
this.companyService = cs;
}
@RequestMapping(value = "/companies", method = RequestMethod.GET)
public String listCompanies(Model model) {
model.addAttribute("company", new Company());
model.addAttribute("listCompanies", this.companyService.listCompanies());
return "company";
}
//For add and update person both
@RequestMapping(value= "/company/add", method = RequestMethod.POST)
public String addCompany(@ModelAttribute("company") Company c){
if(c.getId() == 0){
//new person, add it
this.companyService.addCompany(c);
}else{
//existing person, call update
this.companyService.updateCompany(c);
}
return "redirect:/companies";
}
@RequestMapping("/remove/{id}")
public String removeCompany(@PathVariable("id") int id){
this.companyService.removeCompany(id);
return "redirect:/companies";
}
@RequestMapping("/edit/{id}")
public String editCompany(@PathVariable("id") int id, Model model){
model.addAttribute("company", this.companyService.getCompanyById(id));
model.addAttribute("listCompanies", this.companyService.listCompanies());
return "company";
}
}