当前位置: 首页 > 知识库问答 >
问题:

Spring MVC中的未定义bean

双元魁
2023-03-14
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/config/root-context.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>RESTServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/config/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>
    <servlet-mapping>
        <servlet-name>RESTServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>
<?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:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <!-- Root Context: defines shared resources visible to all other web components -->

    <context:component-scan base-package="com.dynamease.**" />
    <context:annotation-config />

    <!-- Configures External Property Resolution -->
    <import resource="properties.xml" />

    <!-- Configures Shared Data Access Resources -->
    <import resource="data.xml" />

    <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
        <property name="url" value="ldap://192.168.1.10:10389" />
        <property name="base" value="dc=dynamease,dc=net" />
        <property name="userDn" value="uid=admin,ou=system" />
        <property name="password" value="secret" />
    </bean>
    <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
        <constructor-arg ref="contextSource" />
    </bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
    xsi:schemaLocation="
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <!-- DispatcherServlet Context: defines this servlet's request-processing 
        infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <interceptors>
        <beans:bean
            class="com.dynamease.entity.springsocialentities.UserInterceptor">
            <beans:constructor-arg ref="usersConnectionRepository" />
        </beans:bean>
    </interceptors>

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving 
        up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources 
        in the /WEB-INF/views directory -->
    <beans:bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

    <!-- Imports user-defined @Controller beans that process client requests -->
    <bean class="com.dynamease.web.rest.HomeController">
        <constructor-arg ref="facebook" />
    </bean>

    <!-- Allows users to sign-in with their provider accounts.  -->
    <bean class="org.springframework.social.connect.web.ProviderSignInController">
        <constructor-arg ref="connectionFactoryLocator" />
        <constructor-arg ref="usersConnectionRepository" />     
        <constructor-arg>
            <bean class="com.dynamease.entity.springsocialentities.SimpleSignInAdapter" />
        </constructor-arg>
    </bean>

    <mvc:view-controller path="/signin" />

    <mvc:view-controller path="/signout" />
</beans:beans>
@Autowired
    private DynDirectoryServiceImpl dynDirectoryService;

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String home(Model model) {
        System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
        System.out.println(this.getClass().toString());
        System.out.println(dynDirectoryService.toString()); 
}

下面是DynDirectoryServiceImpl代码:

    @Component
    public class DynDirectoryServiceImpl implements DynDirectoryServiceInterface {

        @Autowired
        private LdapTemplate ldapTemplate;

        @Autowired
        private OdmManager odmManager;

        @Override
        public boolean verify(DynContact dynContact) {
            // TODO Auto-generated method stub
            return false;
        }
}

共有1个答案

佴波鸿
2023-03-14

尝试改变autowired财产的类型:

@Autowired
private DynDirectoryServiceInterface

您还错过了

<context:annotation-config />

元素。

 类似资料:
  • 我试图按照这篇文章将cucumber规格与IntelliJ中的步骤定义相匹配。 当我按Alt Enter时,我看到检查未定义的步骤选项。但是,我应该看到意图操作创建步骤定义。 我想我已经安装了Cucumber IntelliJ插件,所以这应该不是问题。非常感谢任何帮助。

  • 问题内容: 注意:根据 ECMAScript5.1,第15.1.1.3节,window.undefined是只读的。 现代浏览器正确地实现了这一点。 例如:Safari 5.1,Firefox 7,Chrome 20等。 Undefined仍可在以下位置更改:Chrome 14,… 原来,问题的原因是 如果“对象”中没有属性“ x”,则返回false。 我通过在两个Facebook函数中用规则相等

  • 问题内容: 嗨,我只是想接收一个ajax请求,但是问题是在React中没有定义jquery。反应版本是 错误信息 我有两个文件 : 问题答案: 尝试添加到您的项目中,例如 或者如果您使用凉亭 然后

  • 我得到一个错误“Uncathed ReferenceError:regeneratorRuntime未定义”。请帮助我找出错误,以及如何解决它。

  • 这条规则似乎在最新版本的Bazel中被否决了,在Bazel0.29.1中有类似的代码吗?

  • 尽管标题出现了,但这并不是一个哲学问题。 从未初始化的数组读取 使用错误数据 使用不可移植构造。(即内存分配的细节1) 导致具有的行为 标准没有要求产生可预测的效果 我会称之为“未定义的行为”。但也许我错过了什么(?) null null