每次在启动控制台的时候,都会提示这样的错误,不知道是什么原因,Error creating bean with name 'contactManagerSecurity' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [org.acegisecurity.intercept.method.MethodDefinitionSource] for property 'objectDefinitionSource'; nested exception is java.lang.IllegalArgumentException: 'select' is not a valid method name: format is FQN.methodName
Caused by: 
org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [org.acegisecurity.intercept.method.MethodDefinitionSource] for property 'objectDefinitionSource'; nested exception is java.lang.IllegalArgumentException: 'select' is not a valid method name: format is FQN.methodName
Caused by: 
java.lang.IllegalArgumentException: 'select' is not a valid method name: format is FQN.methodName
applicationcontext.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"><bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.microsoft.jdbc.sqlserver.SQLServerDriver">
</property>
<property name="url"
value="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=web">
</property>
<property name="username" value="sa"></property>
<property name="password" value="123"></property>
</bean>

<bean id="sessionfactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="hibernate.connection.autocommit">true</prop>
</props>
</property>
<property name="mappingResources">

<list>
<value>dao/Login.hbm.xml</value>
<value>logs/dao/Logs.hbm.xml</value>
</list>
</property>
</bean>
<bean id="LoginDAO" class="dao.LoginDAO">        
<property name="sessionFactory">
<ref bean="sessionfactory" />
</property>
</bean>
<bean id="loginDAOservice" class="service.LoginDAOservice"
abstract="false" lazy-init="default" autowire="default"
dependency-check="default">
<property name="dao">
<ref local="LoginDAO" />
</property>
</bean> <bean name="/insert" class="org.tie.struts.action.InsertAction"
abstract="false" lazy-init="default" autowire="default"
dependency-check="default">
<property name="service">
<ref local="loginDAOservice" />
</property>
</bean>
<bean name="/usershow" class="org.tie.struts.action.UsershowAction"
abstract="false" lazy-init="default" autowire="default"
dependency-check="default">
<property name="service">
<ref local="loginDAOservice" />
</property>
</bean>
<!-- 配置事务管理器,使用Hibernate局部事务管理器策略 -->
<bean id="trasanManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionfactory" />
</property>
</bean>
<!-- 事务拦截器bean需要依赖注入一个事务管理器 --> <bean id="transactinInsertcerptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref local="trasanManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- 定义BeanNameAutoProxyCreator  事物自动代理-->
<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>LoginDAO</value>
</list>
</property>
<!-- 下面定义BeanNameAutoProxyCreator所需的事务拦截器-->
<property name="interceptorNames">
<list>
<value>transactinInsertcerptor</value>
<value>badivce</value>
<value>contactManagerSecurity</value>
</list>
</property>
</bean>

<!-- logs相关设置-->
<bean id="LogsDAO" class="logs.dao.LogsDAO">
<property name="sessionFactory">
<ref local="sessionfactory"/>
</property>
</bean>
<!-- logs监控类 -->
<bean id="badivce" class="service.Badivce" >
<property name="dao">
<ref local="LogsDAO"/>
</property>
</bean>

<!--acegi相关配置 -->
<bean id="businessAccessDecisionManager" class="org.acegisecurity.vote.AffirmativeBased">
   <property name="allowIfAllAbstainDecisions" value="false"/>
<property name="decisionVoters">
<list>
<ref bean="roleVoter" />
</list>
</property>
  </bean>  <bean id="contactManagerSecurity" class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
     <property name="authenticationManager"><ref bean="authenticationManager"/></property>
     <property name="accessDecisionManager"><ref bean="businessAccessDecisionManager"/></property>
     <property name="objectDefinitionSource">
        <value>
          select authority,PROTECTED_RES from authorities where AUTH_TYPE='FUNCTION' and authority like 'AUTH_FUNC_ContactManager%'
        </value>
     </property>
  </bean>
</beans>


请各位大哥,大姐多多指教!谢谢了!!

解决方案 »

  1.   

    使用  select authority,PROTECTED_RES from authorities where AUTH_TYPE='FUNCTION' and authority like 'AUTH_FUNC_ContactManager%'
    是我在一个完全可用的例子中找到的,但是用的我的项目中就不行了,不知道是什么原因,请高手们给小弟指点一二!万分感谢了!
      

  2.   

    很显然,楼主只是按着读XML文档来进行权限配置,而这里是用SELECT。。语句到数据库中进行权限配置,1楼的大哥也只是说了对XML文档中进行权限配置
    用要SELECT语句进行数据库配置,需对objectDefinitionSource的读取方式进行修改,加入这段以XML文件中  <bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
        <property name="customEditors">
          <map>
            <entry key="org.acegisecurity.intercept.method.MethodDefinitionSource">
              <bean class="sample.util.DataSourceMethodDefinitionSourceEditor">
                <property name="jdbcTemplate"> <ref bean="jdbcTemplate"/> </property>
              </bean>
            </entry>
          </map>
        </property>
      </bean>这样对数据库的读取交到了DataSourceMethodDefinitionSourceEditor类中,如下
    import java.beans.PropertyEditorSupport;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;import org.acegisecurity.ConfigAttributeDefinition;
    import org.acegisecurity.ConfigAttributeEditor;
    import org.acegisecurity.intercept.method.MethodDefinitionMap;
    import org.springframework.jdbc.core.JdbcTemplate;public class DataSourceMethodDefinitionSourceEditor extends PropertyEditorSupport{
      protected JdbcTemplate jdbcTemplate;
      //~ Methods ================================================================
      public JdbcTemplate getJdbcTemplate(){
        return jdbcTemplate;
      }   public void setJdbcTemplate(JdbcTemplate jdbcTemplate){
        this.jdbcTemplate=jdbcTemplate;
      }   public void setAsText(String s) throws IllegalArgumentException{
        MethodDefinitionMap source=new MethodDefinitionMap();
        List rs;
        try{
          rs=jdbcTemplate.queryForList(s);
        } catch(Exception e){
          setValue(source);
          e.printStackTrace();
          return;
        }
        if((rs==null)||rs.size()==0){
          // Leave value in property editor null
        } else{
          // Now we have properties, process each one individually
          ConfigAttributeEditor configAttribEd=new ConfigAttributeEditor();       for(Iterator iter=rs.iterator();iter.hasNext();){
            Map row=(Map)iter.next();
            String authority=(String)row.get("AUTHORITY");
            String resource=(String)row.get("PROTECTED_RES");
            if((null==authority)||(resource==null)){
              continue;
            }
            // Convert value to series of security configuration attributes
            configAttribEd.setAsText(authority);
            ConfigAttributeDefinition attr=(ConfigAttributeDefinition)configAttribEd .getValue();
            // Register name and attribute
            source.addSecureMethod(resource, attr);
          }
        }
        setValue(source);
      } }楼主也可以看看ACEGI的一些文档实例,里面的说得很清楚