春季扫描在包含过滤器类型=注释时不起作用,但在类型=正则表达式时起作用

时间:2018-12-29 07:34:56

标签: spring spring-mvc jsf spring-config spring-filter

尝试将应用程序从weblogic移至jboss。 陷入与bean创建相关的问题。...创建了一个示例项目来模拟该问题。

在单独的问题Spring beans not getting created as required by myfaces中提到了

应用程序问题 请检查您是否可以提供帮助..... 屏幕上显示以下消息

“ JSF 2 + Spring集成”;

当我使用include-filter类型进行正则表达式但未在注释期间使用

package com.mkyong;

import javax.inject.Inject;
import com.mkyong.user.bo.UserBo;

public class UserBean {

@Inject
UserBo userBo;

public void setUserBo(UserBo userBo) {
    this.userBo = userBo;
}

public String printMsgFromSpring() {
    return userBo.getMessage();
}

}

UserBO

package com.mkyong.user.bo;

public interface UserBo{

public String getMessage();

}

UserBoImpl

package com.mkyong.user.bo.impl;

import com.mkyong.user.bo.UserBo;

public class UserBoImpl implements UserBo{

public String getMessage() {

    return "JSF 2 + Spring Integration";

}

}

JSF文件(xhtml)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"   
  xmlns:h="http://java.sun.com/jsf/html"
  >

<h:body>

    <h1>JSF 2.0 + Spring Example</h1>
<h:outputText value="#{userBean.printMsgFromSpring()}"></h:outputText> 


</h:body>

</html>

应用程序上下文工作扫描

<context:component-scan base-package="com.mkyong">
 <context:include-filter type="regex" expression="com.mkyong.*" />
</context:component-scan>

当我将其更改为时,应用程序无法正常工作

<context:component-scan base-package="com.mkyong">
    <context:include-filter type="annotation" expression="poc.filter.CustomController"/>
</context:component-scan>

自定义过滤器类

package poc.filter;

import javax.inject.Named;

@Named
public @interface CustomController {

}

pom.xml

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>3.1.2.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>3.1.2.RELEASE</version>
    </dependency>

    <!-- JSF -->
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.1.13</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.1.13</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
    </dependency>

    <!-- EL -->
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>el-impl</artifactId>
        <version>2.2</version>
    </dependency>

    <!-- Tomcat 6 need this -->
    <dependency>
        <groupId>com.sun.el</groupId>
        <artifactId>el-ri</artifactId>
        <version>1.0</version>
    </dependency>

    <!-- JSR-330 --> 
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>

0 个答案:

没有答案