首页 新闻 赞助 找找看

java.lang.NoClassDefFoundError: org.springframework.beans.FatalBeanException

0
悬赏园豆:5 [待解决问题]

最近在一家公司实习,看到公司的项目框架,自己就手痒,搭一个玩玩,用的springmvc(之前是做PHP的)。

定义两个properties文件分别是:redis.properties和mysql.properties.

为了保障信息的安全,使用DES加密(双向的).

在applicationContext.xml文件中配置:


<?xml version="1.0" encoding="UTF-8"?>
<!-- 使用P元素 -->


<!-- service 引入aop和tx命名空间所对应的schema文件 -->


<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:util="http://www.springframework.org/schema/util" 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-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.0.xsd

http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
default-autowire="byName">


<!-- 配置dao -->
<!-- 第一步 扫描包 间标注 Spring 注解的类自动转化为bean 配置sql -->
<context:component-scan base-package="com.znet" />
<!-- 扫描service 应用Spring 的注解配置 -->
<context:component-scan base-package="com.znet" />


<!-- <context:property-placeholder location="classpath:mysql.properties"
/> 引入自定义文件 设置mysql 文件 -->
<bean id="propertyConfigurer" class="com.znet.global.conf.EncryptPropPlaceholderConfig">
<property name="fileEncoding" value="utf-8" />
<property name="order" value="0" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="locations">
<list>
<value>classpath:mysql.properties</value>
<value>classpath:redis.properties</value>
</list>
</property>
</bean>


 


<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close" p:driverClassName="${driver}" p:url="${url}"
p:password="${passwd}" p:username="${user}" />


<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>



<!--redis池配置信息 -->
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig" />
<!-- redis 链接工厂配置 -->
<bean id="connectionFactory" destroy-method="destroy"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:hostName="***.**.**.**" p:port="6378" p:password="******"
p:poolConfig-ref="poolConfig" />
<!-- redisTemplete -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate"
p:connectionFactory-ref="connectionFactory" />
<!-- -配置redis文件 end -->



<!-- 配置service -->
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="dataSource"></bean>


<!-- 通过aop配置提供失去增强,让service包下 所有的bean的所有方法拥有事务 -->
<aop:config proxy-target-class="true">
<aop:pointcut id="serviceMethod" expression="execution(* com.znet..*.*(..))"></aop:pointcut>
<aop:advisor pointcut-ref="serviceMethod" advice-ref="txAdvice"></aop:advisor>


</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*"></tx:method>
</tx:attributes>
</tx:advice>


</beans>



这样的话就会出现:

java.lang.NoClassDefFoundError: org.springframework.beans.FatalBeanException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1037)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:983)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:633)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:120)
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:248)
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
    at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:122)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

但是单独使用,只有像如下这样配置:

    <bean class="com.znet.global.conf.EncryptPropPlaceholderConfig"
        p:locations="classpath:mysql.properties" p:fileEncoding="utf-8">
    </bean>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close" p:driverClassName="${driver}" p:url="${url}"
        p:password="${passwd}" p:username="${user}" />

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

<!--另外一个只能 这样配置--->
<!--redis池配置信息 -->
    <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig" />
    <!-- redis 链接工厂配置 -->
    <bean id="connectionFactory" destroy-method="destroy"
        class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
        p:hostName="$***.**.**.**" p:port="6378" p:password="$******"
        p:poolConfig-ref="poolConfig" />
    <!-- redisTemplete -->
    <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate"
        p:connectionFactory-ref="connectionFactory" />
    <!-- -配置redis文件 end -->

才可以使用

就算配置两个

com.znet.global.conf.EncryptPropPlaceholderConfig  也不能使用。
另附
com.znet.global.conf.EncryptPropPlaceholderConfig的代码 和DESUtil代码,希望有人能帮忙解决。
package com.znet.global.conf;

import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

import com.znet.global.util.DESUtil;

/**
 * 加密
 * 
 * @author net com.eams.common.conf.EncryptPropPlaceholderConfig
 */
public class EncryptPropPlaceholderConfig extends PropertyPlaceholderConfigurer {

    private String[] encodePropName = {"passwd", "user", "redis.passwd",
            "redis.hostname"};

    protected String convertProperty(String propertyName, String propertyValue) {
        if (isEncryptProp(propertyName)) {
            return DESUtil.decode(propertyValue);
        } else {
            return propertyValue;
        }
    }

    private boolean isEncryptProp(String ecodePropName) {
        for (String propName : encodePropName) {
            if (propName.equals(ecodePropName)) {
                return true;
            }
        }

        return false;
    }

}
package com.znet.global.util;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Random;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class DESUtil {

    public static Key key;
    // 秘钥
    public static String secretKey = SecurityUtil.str2MD5("********");

    static {
        try {
            KeyGenerator keyGenerator = KeyGenerator.getInstance("DES");
            keyGenerator.init(new SecureRandom(secretKey.getBytes("utf-8")));
            key = keyGenerator.generateKey();
            keyGenerator = null;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            LoggerUtil.error(DESUtil.class, e.getMessage());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            LoggerUtil.error(DESUtil.class, e.getMessage());
        }
    }

    public static String encode(String str) {
        BASE64Encoder encoder = new BASE64Encoder();
        try {
            Cipher cipher = Cipher.getInstance("DES");
            cipher.init(Cipher.ENCRYPT_MODE, key);
            return encoder.encode(cipher.doFinal(str.getBytes("utf-8")));
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            LoggerUtil.error(DESUtil.class, e.getMessage());
        } catch (NoSuchPaddingException e) {
            e.printStackTrace();
            LoggerUtil.error(DESUtil.class, e.getMessage());
        } catch (InvalidKeyException e) {
            e.printStackTrace();
            LoggerUtil.error(DESUtil.class, e.getMessage());
        } catch (IllegalBlockSizeException e) {
            e.printStackTrace();
            LoggerUtil.error(DESUtil.class, e.getMessage());
        } catch (BadPaddingException e) {
            e.printStackTrace();
            LoggerUtil.error(DESUtil.class, e.getMessage());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            LoggerUtil.error(DESUtil.class, e.getMessage());
        }
        return null;
    }

    public static String decode(String str) {
        BASE64Decoder decoder = new BASE64Decoder();
        try {
            Cipher cipher = Cipher.getInstance("DES");
            cipher.init(Cipher.DECRYPT_MODE, key);
        return     new String(cipher.doFinal(decoder.decodeBuffer(str)), "utf-8");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            LoggerUtil.error(DESUtil.class, e.getMessage());
        } catch (NoSuchPaddingException e) {
            LoggerUtil.error(DESUtil.class, e.getMessage());
            e.printStackTrace();
        } catch (InvalidKeyException e) {
            LoggerUtil.error(DESUtil.class, e.getMessage());
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            LoggerUtil.error(DESUtil.class, e.getMessage());
            e.printStackTrace();
        } catch (IllegalBlockSizeException e) {
            LoggerUtil.error(DESUtil.class, e.getMessage());
            e.printStackTrace();
        } catch (BadPaddingException e) {
            LoggerUtil.error(DESUtil.class, e.getMessage());
            e.printStackTrace();
        } catch (IOException e) {
            LoggerUtil.error(DESUtil.class, e.getMessage());
            e.printStackTrace();
        }

        return null;
    }

    

    public static void main(String[] args) {

    }

}

 

 
 
搬砖工奶爸的主页 搬砖工奶爸 | 初学一级 | 园豆:184
提问于:2016-05-09 12:15
< >
分享
所有回答(2)
0

其实你可以看一下抛的这个异常是怎么解释的:


* Thrown on an unrecoverable problem encountered in the
* beans packages or sub-packages, e.g. bad class or field.

估计是你的上面的那个配置文件bean的参数写的有问题。

Hotsum | 园豆:197 (初学一级) | 2016-05-09 21:26

谢谢回复,问题已经解决.

支持(0) 反对(0) 搬砖工奶爸 | 园豆:184 (初学一级) | 2016-05-10 09:44

@小net: 最后怎么解决的?

支持(0) 反对(0) Hotsum | 园豆:197 (初学一级) | 2016-05-10 14:23

@Hotsum: 好像配置没有问题,看下面那条我的描述

支持(0) 反对(0) 搬砖工奶爸 | 园豆:184 (初学一级) | 2016-05-10 20:49
0

首先描述下吧,昨天晚上用自己的电脑把个项目重新搭建了一下,当然也把redis 的密码设置一下,随机生成的五十位,采用的是des加密,按照上述流程走了一遍,没有任何问题,我本机使用的tomcat7,而公司使用的是myeclipse自带的tomcat(自己配置的tomcat只能跑公司项目,自己的会出错),两者有区别的,具体区别我也不是很了解,今天早晨上班,把 手头工作做完,又重新走了一遍,都可以走的通,还有一点就是使用SpringJuit4测试时,好多对象不能自动实例化,像sRedis,redisTemplate,而我的加强是整个框架下的所有包类(避免麻烦),我自己也不是很理解(才接触springmvc,不到两个月,也在学)。希望有人看到可以解释下。

在这里问一下:一个web项目,用maven管理,有log输出信息(方便差错,一日一个文件),有数据库mysql,有redis(缓存信息),有过滤器等基本配置,能算的上一个小项目吗?

这里粘贴处对应的信息。使用的tomcat是myeclipse自带的。 我尽量把使用到的代码撵出来,让问题更具体.

测试代码 

package com.znet.global.spring.redis;

import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.znet.global.spring.model.User;
import com.znet.global.util.RandUtils;
import com.znet.global.util.SecurityUtil;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/applicationContext.xml"})
public class TestSRedis {

    private static String preString = "ZNET";

    private static SRedis sRedis = new SRedis();

    @Test
    public void add() {
        String id = RandUtils.getUUId();
        String name = RandUtils.createCName(30);
        System.out.println(id + "\t" + name);
        String key = preString + SecurityUtil.str2MD5(id + name);
        System.out.println(key);
        User user = new User(id, name);
        sRedis.add(key, user);
    }

    @Test
    public void get() {
        // ZNETf892f927b37a05df5bf42dab04cd5a04
        String key = "ZNET3951ae263be2f79e9e0f2139b3dba9e1";
        User user = sRedis.get(key);
        if (user != null) {
            System.out.println(user.toString());
        }
    }

    @Test
    public void fuzzyGet() {
        String pattrn = "*ZNET*";
        List<User> users = sRedis.fuzzyGet(pattrn);
        for (User user : users) {
            System.out.println(user.toString());
        }

    }

}

自己简单的封装的redisTemplate操作.  这里不能自己实例化,才采用下面

package com.znet.global.spring.redis;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisConnectionUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

import com.znet.global.spring.model.User;

public class SRedis {

    public SRedis() {
        ApplicationContext appContext = new ClassPathXmlApplicationContext(
                "classpath:/applicationContext.xml");
        redisTemplate = (RedisTemplate<?, ?>) appContext
                .getBean("redisTemplate");
    }

    private RedisTemplate<?, ?> redisTemplate;

    public static void main(String[] args) {
        new SRedis();
    }

    public boolean add(final String key, final User user) {
        return (Boolean) redisTemplate.execute(new RedisCallback<Boolean>() {

            public Boolean doInRedis(RedisConnection connection)
                    throws DataAccessException {
                RedisSerializer<String> redisSerializer = redisTemplate
                        .getStringSerializer();
                byte[] keyByte = redisSerializer.serialize(key);
                byte[] valueByte = redisSerializer.serialize(user.toString());
                boolean isSus = connection.setNX(keyByte, valueByte);
                //
                return isSus;
            }
        });
    }

    public User get(final String key) {
        return redisTemplate.execute(new RedisCallback<User>() {
            public User doInRedis(RedisConnection connection)
                    throws DataAccessException {
                byte[] keyByte = redisTemplate.getStringSerializer().serialize(
                        key);
                byte[] valueByte = connection.get(keyByte);
                String str = redisTemplate.getStringSerializer().deserialize(
                        valueByte);
                return new User(str);
            }
        });
    }
    public List<User> fuzzyGet(String pattrn) {
        List<User> users = new ArrayList<User>();
        RedisConnectionFactory redisConnectionFactory = redisTemplate
                .getConnectionFactory();
        RedisConnectionUtils.bindConnection(redisConnectionFactory);
        try {
            Object obj = redisConnectionFactory.getConnection().execute("keys",
                    pattrn.getBytes());
            ArrayList<byte[]> bys = (ArrayList<byte[]>) obj;
            for (byte[] by : bys) {
                if (by != null && by.length > 0) {
                    String temp = (String) redisTemplate.getStringSerializer()
                            .deserialize(by);
                    String str = (String) redisTemplate.opsForValue().get(temp);
                    System.out.println(temp);
                    users.add(new User(str));
                }
            }
            return users;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            RedisConnectionUtils.unbindConnection(redisConnectionFactory);
        }
        return users;
    }

}

 

redis配置

redis.hostname=************
redis.port1=6378
redis.port2=6379
redis.port3=6380
redis.passwd=*************
redis.maxToatl=2000
redis.maxIdle=20
redis.testOnBorrow=true
redis.maxWaitMills=1000

mysql配置

mysql.dbname=springdb
mysql.driver=com.mysql.jdbc.Driver
mysql.url=jdbc:mysql://localhost:3306/${mysql.dbname}
mysql.passwd=**********
mysql.user=**********

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- 使用P元素 -->
<!-- service 引入aop和tx命名空间所对应的schema文件 -->
<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:util="http://www.springframework.org/schema/util" 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-2.5.xsd 
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-2.5.xsd
      http://www.springframework.org/schema/util 
      http://www.springframework.org/schema/util/spring-util-2.0.xsd
      
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
      http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
    default-autowire="byName">

    <!-- 配置dao -->
    <!-- 第一步 扫描包 间标注 Spring 注解的类自动转化为bean 配置sql com.eams.ch1.dao -->
    <context:component-scan base-package="com.znet" />
    <!-- 扫描service雷暴 应用Spring 的注解配置 com.eams.ch1.service -->
    <context:component-scan base-package="com.znet" />

    <!-- <context:property-placeholder location="classpath:mysql.properties" 
        /> 引入自定义文件 设置mysql 文件 -->
    <bean class="com.znet.global.conf.EncryptPropPlaceholderConfig"
        p:fileEncoding="utf-8">
        <property name="locations">
            <list>
                <value>classpath:mysql.properties</value>
                <value>classpath:redis.properties</value>
            </list>
        </property>
    </bean>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close" p:driverClassName="${mysql.driver}" p:url="${mysql.url}"
        p:password="${mysql.passwd}" p:username="${mysql.user}" />

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="dataSource"></property>
    </bean>


    <!--redis池配置信息 -->
    <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig"
        p:maxTotal="${redis.maxToatl}" p:maxIdle="${redis.maxIdle}"
        p:testOnBorrow="true" p:maxWaitMillis="${redis.maxWaitMills}" />
    <!-- redis 链接工厂配置 -->
    <bean id="connectionFactory"
        class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
        p:hostName="${redis.hostname}" p:port="${redis.port2}"
        p:poolConfig-ref="poolConfig" p:password="${redis.passwd}" />
    <!-- redisTemplete -->
    <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate"
        p:connectionFactory-ref="connectionFactory" />
    <!-- -配置redis文件 end -->

    <!-- 配置事务管理器 -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
        p:dataSource-ref="dataSource"></bean>



    <!-- 通过aop配置提供失去增强,让service包下 所有的bean的所有方法拥有事务 -->
    <aop:config proxy-target-class="true">
        <aop:pointcut id="serviceMethod" expression="execution(* com.znet..*.*(..))"></aop:pointcut>
        <aop:advisor pointcut-ref="serviceMethod" advice-ref="txAdvice"></aop:advisor>

    </aop:config>
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="*"></tx:method>
        </tx:attributes>
    </tx:advice>



</beans>

EncryptPropPlaceholderConfig

package com.znet.global.conf;

import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

import com.znet.global.util.DESUtil;

/**
 * 加密
 * 
 * @author net com.eams.common.conf.EncryptPropPlaceholderConfig
 */
public class EncryptPropPlaceholderConfig extends PropertyPlaceholderConfigurer {

    private String[] encodePropName = {"mysql.passwd", "mysql.user",
            "redis.hostname", "redis.passwd"};

    protected String convertProperty(String propertyName, String propertyValue) {

        if (isEncryptProp(propertyName)) {
            return DESUtil.decode(propertyValue);
        } else {
            return propertyValue;
        }
    }

    private boolean isEncryptProp(String ecodePropName) {
        for (String propName : encodePropName) {
            if (propName.equals(ecodePropName)) {
                return true;
            }
        }

        return false;
    }

}

 

 

搬砖工奶爸 | 园豆:184 (初学一级) | 2016-05-10 10:09
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册