我试图在春天mvc中自动装载一个字段。但是我得到了一个例外:
" servlet调度程序的Servlet.init()抛出异常"
我尝试了Injection of autowired dependencies failed
但我仍然得到这个例外:
type Exception report
message Servlet.init() for servlet dispatcher threw exception
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet.init() for servlet dispatcher threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1575)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1533)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:744)
root cause
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'careerController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: DAO.CareerDAO controller.CareerController.cardao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [DAO.CareerDAO] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1575)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1533)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:744)
root cause
org.springframework.beans.factory.BeanCreationException: Could not autowire field: DAO.CareerDAO controller.CareerController.cardao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [DAO.CareerDAO] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508)
org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1575)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1533)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:744)
root cause
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [DAO.CareerDAO] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1100)
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:960)
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:855)
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1575)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1533)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:744)
我的dispatcher-servlet.xml是:
<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?xml version="1.0" encoding="UTF-8"?> -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:component-scan base-package="controller"></context:component-scan>
<context:component-scan base-package="bean"></context:component-scan>
<context:component-scan base-package="DAO"></context:component-scan>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<bean id="con" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/intelliLABS"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<!-- normal jdbc template bean-->
<bean id="template" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="con"></property>
</bean>
<!-- For sending email,adding spring's mail support -->
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.gmail.com" />
<property name="username" value="MYMAIL" />
<property name="password" value="MYPASSWORD" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.socketFactory.port">465</prop>
<prop key="mail.smtp.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
<prop key="mail.smtp.port">465</prop>
</props>
</property>
</bean>
<bean id="mailMail" class="bean.MailMail">
<property name="mailSender" ref="mailSender" />
</bean>
<!-- this bean uses normal jdbc template -->
<bean id="contactsDAO" class="DAO.ContactsDAO">
<property name="jdbc" ref="template"></property>
</bean>
<!-- this bean uses normal jdbc template -->
<bean id="vacancyDAO" class="DAO.VacancyDAO">
<property name="jdbc1" ref="template"></property>
</bean>
<!-- this bean uses normal jdbc template -->
<bean id="careerDAO" class="DAO.CareerDAO">
<property name="jdbc2" ref="template"></property>
</bean>
</beans>
以下是我的课程:
package bean;
/**
*
* @author Anjana
*/
public class Career {
int a_id;
String name;
String address;
String email;
String phone;
String resumeDoc;
int VacancyId;
String dateApplied;
//constructors
public Career() {
}
public Career(int VacancyId) {
this.VacancyId = VacancyId;
}
public Career(String name, String address, String email, String phone, String resumeDoc, int VacancyId, String dateApplied) {
this.name = name;
this.address = address;
this.email = email;
this.phone = phone;
this.resumeDoc = resumeDoc;
this.VacancyId = VacancyId;
this.dateApplied = dateApplied;
}
//getters
public int getA_id() {
return a_id;
}
public String getName() {
return name;
}
public String getAddress() {
return address;
}
public String getEmail() {
return email;
}
public String getPhone() {
return phone;
}
public String getResumeDoc() {
return resumeDoc;
}
public int getVacancyId() {
return VacancyId;
}
public String getDateApplied() {
return dateApplied;
}
//setters
public void setA_id(int a_id) {
this.a_id = a_id;
}
public void setName(String name) {
this.name = name;
}
public void setAddress(String address) {
this.address = address;
}
public void setEmail(String email) {
this.email = email;
}
public void setPhone(String phone) {
this.phone = phone;
}
public void setResumeDoc(String resumeDoc) {
this.resumeDoc = resumeDoc;
}
public void setVacancyId(int VacancyId) {
this.VacancyId = VacancyId;
}
public void setDateApplied(String dateApplied) {
this.dateApplied = dateApplied;
}
}
DAO课程:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package DAO;
import bean.Career;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ResultSetExtractor;
/**
*
* @author Anjana
*/
public class CareerDAO {
//injected
JdbcTemplate jdbc2;
//setter
public void setJdbc2(JdbcTemplate jdbc2) {
this.jdbc2 = jdbc2;
}
//methods to access database data
//insertion
//----------------------------------------------------------------------
public int insertion(Career car)
{
String insertQuery="insert into careers(name,address,email,phone,resumeDoc,vacancyId,dateApplied) values('"
+ car.getName()+ "','" + car.getAddress()+ "','"
+ car.getEmail()+ "','" + car.getPhone()+ "','"+ car.getResumeDoc()+ "','"
+ car.getVacancyId()+ "','" +car.getDateApplied()+ "')";
return jdbc2.update(insertQuery);
}
//deletion
//----------------------------------------------------------------------
public int deletion(int a_id) {
String deleteQuery = "delete from careers where id='" +a_id + "'";
return jdbc2.update(deleteQuery);
}
//retrieve all to display
//----------------------------------------------------------------------
public List retrievedata() {
String displayquery = "select * from careers";
return jdbc2.query(displayquery, new ResultSetExtractor<List<Career>>() {
@Override
public List<Career> extractData(ResultSet rs) throws SQLException, DataAccessException {
List<Career> list = new ArrayList<>();
while (rs.next()) {
Career cr = new Career();
cr.setA_id(rs.getInt(1));
cr.setName(rs.getString(2));
cr.setAddress(rs.getString(3));
cr.setEmail(rs.getString(4));
cr.setPhone(rs.getString(5));
cr.setResumeDoc(rs.getString(6));
cr.setVacancyId(rs.getInt(7));
cr.setDateApplied(rs.getString(8));
list.add(cr);
}
return list;
}
});
}
//retrieve only one row
//----------------------------------------------------------------------
public Career retrieveProfile(int a_id) {
//returnig the details as an object of Career
//using queryForObject() and BeanPropertyRowMapper
String displayquery = "select * from careers where id=?";
return jdbc2.queryForObject(displayquery, new Object[]{a_id}, new BeanPropertyRowMapper<Career>(Career.class));
}
}
控制器类:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package controller;
import DAO.CareerDAO;
import bean.Career;
import bean.MailMail;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
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 org.springframework.web.servlet.ModelAndView;
/**
*
* @author Anjana
*/
@Controller
public class CareerController {
//inject objects of dao class
@Autowired
CareerDAO cardao;
//inject objects of dao class
// @Autowired
// VacancyDAO Vdao;
//inject objects of JavaMailSender class
@Autowired
private MailMail m;
public CareerDAO getCardao() {
return cardao;
}
public void setCardao(CareerDAO cardao) {
this.cardao = cardao;
}
//go to careers page from index page
//--------------------------------------------------------------------
@RequestMapping("/careersPage")
public ModelAndView ViewVacancyForPublic()
{
return new ModelAndView("redirect:/AllVacancies");
}
//go to Job Application Form
//--------------------------------------------------------------------
@RequestMapping("/ApplicationForm")
public ModelAndView Apply()
{
return new ModelAndView("careers/ApplicationForm","command",new Career());
}
//Add applicant data
//---------------------------------------------------------------
@RequestMapping(value="/ApplySubmit",method=RequestMethod.POST)
public ModelAndView AddApplication(@ModelAttribute Career career)
{
//get current date and time
DateFormat dateformat=new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Date date=new Date();
career.setDateApplied(dateformat.format(date).toString());
//get login Id
//int LoginId= ;
//conta.setDelId(LoginId);
if(cardao.insertion(career)==1)
{
//send mail to the person thanking him
String from1="thisisanjusdummyacc@gmail.com";
String to1 = career.getEmail();
String sub1 = "Thanks";
String msg1 = "Greetings from IntelliLABS!!\n"
+ "We've received your job Application."
+ "\nwe will get back to you as soon as possible.";
m.sendMail(from1, to1,sub1,msg1);
//send mail to admin informing about the application received
String from2="thisisanjusdummyacc@gmail.com";
String to2 = "thisisanjusdummyacc@gmail.com";
String sub2 = "New Job Application through IntelliLABS.com";
String msg2 = "Hai Admin!!\n\n"
+ "New job Application from "+career.getName()+"....\n\n"
// +"For the position : "+Vdao.retrieveVacancyTitle(career.getVacancyId())+"\n\n"
+"Login to the account to view the resume."
+ "And Please reply as soon as possible\n"
+"to the mail : "+career.getEmail();
// sends the e-mail
m.sendMail(from2, to2,sub2,msg2);
//display a message or alert saying "thank you for connecting with us"
System.out.println("insertion successful");
}
else{
//else display "application failed...try agin later in alert"
System.out.println("insertion failed");
}
return new ModelAndView("redirect:/AllVacancies");
}
//display all applicants to only admin
//----------------------------------------------------------------------
@RequestMapping("/ShowApplicants")
public ModelAndView DispAllApplicants()
{
List<Career> profileList= cardao.retrievedata();
return new ModelAndView("admin/ViewProfiles","profileList",profileList);
}
//delete applicant only by admin
//----------------------------------------------------------------------
@RequestMapping(value="/deleteProfile/{a_id}")
public ModelAndView deleteProfile(@PathVariable int a_id)
{
if(cardao.deletion(a_id)==1)
{
System.out.println("Profile "+a_id+" deleted\n");
return new ModelAndView("redirect:/ShowApplicants");
}
else
{
return new ModelAndView("redirect:/failiure");
}
}
//show one profile for admin
//----------------------------------------------------------------------
@RequestMapping(value="/dispProfile/{a_id}")
public ModelAndView viewOneProfile(@PathVariable int a_id)
{
Career prof= cardao.retrieveProfile(a_id);
return new ModelAndView("admin/ApplicantProfile","command",prof);
}
}
有人可以帮我理解这个自动装配问题......
答案 0 :(得分:0)
您应该使用构造型(即Repository或Component)注释标记您的Dao图层bean,如下所示:
@Repository
public class CareerDAO {
//injected
JdbcTemplate jdbc2;
// rest of your logic
}
Spring组件扫描会扫描给定的包并查找构造型注释,例如@Component,@ Service,并创建这些bean并将其注入适当的bean。因为你没有用那些注释标记bean,所以spring还没有创建dao bean。