0

这是我的服务类

@Controller
@RequestMapping("/SchemeMaster.htm")
@SessionAttributes("schemeBean")
public class SchemeController {
    static final Logger logger = Logger.getLogger(SchemeController.class);
    private static final String className = "SchemeController";
    private static String functionName = "";
    private SchemeManager schemeManager;

    @Autowired
    public void setSchemeManager(SchemeManager schemeManager) {
        functionName = "setSchemeManager";
        logger.info("In " + className + " - " + functionName + " ");
        this.schemeManager = schemeManager;
    }
}

这是 SchemeManager 接口

public interface SchemeManager extends Serializable {

    public void addScheme(SchemeBean schemeBean) throws Exception;

    public List<SchemeBean> getScheme(SchemeBean smaster) throws Exception;

    public void updateScheme(SchemeBean schemeBean,String user) throws Exception;

    public SchemeBean editScheme(String schemeName) throws Exception;

    public List<SchemeBean> getProductList() throws Exception;

    public HashMap<String,String> getRiskPlan() throws Exception;

    public HashMap<Integer,String> getModuleId() throws Exception;

}

这是它的实现

public class SchemeManagerImpl implements SchemeManager {

    SchemeDao schemeDao=new SchemeDaoImpl();

    //@Override
    public void addScheme(SchemeBean schemeBean) throws Exception {
        // TODO Auto-generated method stub
        schemeDao.addScheme(schemeBean);
        System.out.println("User added successfully");
    }

//Other methods
}

这是我的 mintDispatcher-servlet.xml

<?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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- the application context definition for the springapp DispatcherServlet -->

    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename" value="com/tcs/rspm/resources/messages"/>
    </bean>
    <context:component-scan base-package="com.tcs.rspm.controller" />
    <bean id="SchemeManager" class="com.tcs.rspm.service.SchemeManagerImpl" />
    <bean id="schemeDao" class="com.tcs.rspm.dao.SchemeDaoImpl" />


     <bean id="SearchCvManager" class="com.tcs.rspm.service.SearchCvManagerImpl"/> 
    <bean id="searchCvDao" class="com.tcs.rspm.dao.SearchCvDaoImpl" />

    <bean id="SearchPcManager" class="com.tcs.rspm.service.SearchPcManagerImpl"/> 
    <bean id="searchPcDao" class="com.tcs.rspm.dao.SearchPcDaoImpl" />

    <bean id="SearchOppManager" class="com.tcs.rspm.service.SearchOpportunityManagerImpl"/> 
    <bean id="searchOppDao" class="com.tcs.rspm.dao.SearchOpportunityDaoImpl" />    

    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />

    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

  <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
        <property name="prefix" value="/WEB-INF/jsp/"></property>
        <property name="suffix" value=".jsp"></property>        
    </bean>   

 <!--   <bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"
        p:definitions="/WEB-INF/tiles-defs.xml" /> -->

</beans>

我得到以下异常

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schemeController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void com.tcs.rspm.controller.SchemeController.setSchemeManager(com.tcs.rspm.service.SchemeManager); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.tcs.rspm.service.SchemeManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
    org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
    org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:900)
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:455)
    org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    com.tcs.rspm.controller.OpportunitySearchController.opportunitySearchResults(OpportunitySearchController.java:48)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

请帮忙

编辑:包括 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>RSPM3</display-name>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/mintDispatcher-service.xml</param-value>
  </context-param>
  <servlet>
    <servlet-name>mintDispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>mintDispatcher</servlet-name>
    <url-pattern>*.htm</url-pattern>
  </servlet-mapping>
  <session-config>
    <session-timeout>30</session-timeout>
  </session-config>
  <jsp-config>
    <taglib>
      <taglib-uri>/spring</taglib-uri>
      <taglib-location>/WEB-INF/tld/spring-form.tld</taglib-location>
    </taglib>
    <taglib>
      <taglib-uri>/c</taglib-uri>
      <taglib-location>/WEB-INF/tld/c.tld</taglib-location>
    </taglib>
  </jsp-config>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>
4

2 回答 2

0

您正在使用 Anontation 和 XML 来创建对象。使用其中之一。

于 2013-10-23T10:00:04.303 回答
0

在实现的服务类中使用@service注释SchemeManagerImpl

@service
public class SchemeManagerImpl implements SchemeManager {
}
于 2013-10-23T06:48:58.600 回答