1,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: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/tx
       http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"
default-lazy-init="true">
<!-- 定义数据源的Bean ,给Hibernate的sessionFactory-->
<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://127.0.0.1:1433;DatabaseName=compass">
</property>
<property name="username" value="sa"></property>
<property name="password" value="sa"></property>
-->

<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url"
value="jdbc:oracle:thin:@Skyman:1521:orcl">
</property>  
<property name="username" value="scott"></property>
<property name="password" value="scott"></property>

</bean> <!-- 定义Hibernate的sessionFactory,通过该Bean,可以获得Hibernate的Session-->
<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.Oracle9Dialect
</prop>

<!-- 
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
-->

<!--设置二级缓冲-->
<prop key="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</prop>
<!--设置二级缓冲,打开查询缓冲-->
<prop key="hibernate.cache.use_query_cache">true</prop>
<!--设置显示Hibernate操作的SQL语句-->
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/v512/example/model/Product.hbm.xml</value>
</list>
</property>
</bean><!-- compass bean config begin on 2009-03-16 -->
<bean id="annotationConfiguration"
class="org.compass.annotations.config.CompassAnnotationsConfiguration">
</bean>

<bean id="compass" class="org.compass.spring.LocalCompassBean">
<property name="resourceDirectoryLocations">
<list>
<value>classpath:com/v512</value>
</list>
</property>
<property name="connection">
<value>classpath:com/v512/indexes</value>
</property>
<property name="classMappings">
<list>
<value>com.v512.example.model.Product</value>
</list>
</property>
<property name="compassConfiguration"
ref="annotationConfiguration" /> <property name="compassSettings">
<props>
<prop key="compass.transaction.factory">
org.compass.spring.transaction.SpringSyncTransactionFactory
</prop>
  <prop key="compass.engine.analyzer.MMAnalyzer.CustomAnalyzer">net.paoding.analysis.analyzer.PaodingAnalyzer </prop>
</props>
</property> <property name="transactionManager" ref="transactionManager" />
</bean>
<bean id="hibernateGpsDevice"
class="org.compass.gps.device.hibernate.HibernateGpsDevice">
<property name="name">
<value>hibernateDevice</value>
</property>
<property name="sessionFactory" ref="sessionFactory" />
<property name="mirrorDataChanges">
<value>true</value>
</property>
</bean>
<!-- 同步更新索引 -->
<bean id="compassGps" class="org.compass.gps.impl.SingleCompassGps"
init-method="start" destroy-method="stop">
<property name="compass" ref="compass" />
<property name="gpsDevices">
<list>
<bean
class="org.compass.spring.device.SpringSyncTransactionGpsDeviceWrapper">
<property name="gpsDevice" ref="hibernateGpsDevice" />
</bean>
</list>
</property>
</bean>
<bean id="compassTemplate"
class="org.compass.core.CompassTemplate">
<property name="compass" ref="compass" />
</bean> <!-- 定时重建索引(利用quartz)或随Spring ApplicationContext启动而重建索引 
<bean id="compassIndexBuilder"
class="com.v512.example.service.impl.CompassIndexBuilder"
>
<property name="compassGps" ref="compassGps" />
<property name="buildIndex" value="true" />
<property name="lazyTime" value="10" />
</bean>
-->

<!--新增【功能整测试过】beign > 自动随Spring ApplicationContext启动而重建索引 -->
<!-- 参考资料:http://jiangyingshan.javaeye.com/blog/89860 -->
<bean id="compassIndexBuilder"
class="com.v512.example.service.impl.CompassIndexBuilder" lazy-init="false">
<property name="compassGps">
<ref local="compassGps" />
</property>
<property name="buildIndex">
<value>true</value>
</property>
<property name="lazyTime">
<value>10</value>
</property>
</bean>
<!--新增【功能未测试过】end > 自动随Spring ApplicationContext启动而重建索引 -->
<!-- 同步更新索引 【正在测试中的功能】 end -->

<!-- compass bean config end -->
<bean id="productDao"
class="com.v512.example.dao.hibernate.ProductDaoHibernate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="productManager"
class="com.v512.example.service.impl.ProductManagerImpl">
<property name="productDao" ref="productDao"></property>
<property name="compassTemplate" ref="compassTemplate"></property>
</bean> <bean id="productBean" class="com.v512.example.action.ProductAction"
scope="prototype">
<property name="productManager" ref="productManager"></property> </bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean> <!-- 配置事务特性 ,配置add、delete和update开始的方法,事务传播特性为required-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice> <!-- 配置那些类的方法进行事务管理,当前cn.com.jobedu.oa.service包中的子包、类中所有方法需要,还需要参考tx:advice的设置 -->
<aop:config>
<aop:pointcut id="allManagerMethod"
expression="execution (* com.v512.example.service.*.*(..))" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="allManagerMethod" />
</aop:config>
</beans>

解决方案 »

  1.   

    2,读取程序java代码如下:
    package test;import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;public class T { public static void main(String args[]){
    T t=new T();
    System.out.println(t.readFile2(new File("1.xml")));
    }
        public static String readFile2(File f){
         // 建立可容纳1024个字符的数组 
            char data[]=new char[1024]; 
            StringBuffer temp = new StringBuffer();   
            // 建立对象fr 
            FileReader fr;
    try {
    fr = new FileReader(f.getCanonicalPath());
    while (fr.read()>1){
            // 将数据读入字符列表data内 
            int num=fr.read(data); 
            // 将字符列表转换成字符串          
            String str=new String(data,0,num); 
            temp.append(str);
    }
            // 输出在控制台 
            fr.close(); 
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();

    String temps=temp.toString();
            //System.out.println(temps); 
    return temps;  
        }  
    }
      

  2.   


    为什么显示字符串如下:?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: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/tx
           http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"
    default-lazy-init="true">
    <!-- 瀹氫箟鏁版嵁婧愮殑Bean 锛岀粰Hibernate鐨剆essionFactory-->
    <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://127.0.0.1:1433;DatabaseName=compss">
    </property>
    <property name="username" value="sa"></property>
    <property name="password" value="sa"></property>
    -->

    <property name="driverClassName"
    value="oracle.jdbc.driver.OracleDriver">
    </property>
    <property name="url"
    value="jdbc:oracle:thin:@Skyman:1521:orcl">
    </property>  
    <property name="username" value="scott"></property>
    <property name="password" value="scott"></property>

    </bean> <!-- 瀹氫箟Hibernate鐨剆essionFactory锛岄?杩囪Bean锛屽彲浠ヨ幏寰桯ibernate鐨凷ession-->
    <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.Oracle9Dialect
    </prop>

    <!-- 
    <prop key="hibernate.dialect">
    org.hibernate.dialect.SQLServerDialect
    </prop>
    -->

    <!--璁剧疆浜岀骇缂撳啿-->
    <prop key="hibernte.cache.provider_class">
    org.hibernate.cache.EhCacheProvider
    </prop>
    <!--璁剧疆浜岀骇缂撳啿锛屾墦寮?煡璇㈢紦鍐?->
    <prop key="hibernate.cache.use_query_cache">true</prop>
    <!--璁剧疆鏄剧ずHibernate鎿嶄綔鐨凷QL璇彞-->
    <prop key="hibernate.show_sql">true</prop>
    </props>
    </property>
    <property name="mappingResources">
    <list>
    <value>com/v512/example/model/Product.hbm.xml</value>
    </list>
    </property>
    </bean><!-- compass bean config begin on 2009-03-16 -->
    <bean id="annotationConfiguration"
    class="org.compass.annotations.config.CompassAnnotationsConfiguration">
    </bean>

    <bean id="compass" class="org.compass.spring.LocalCompassBean">
    <property name="resourceDirectoryLocations">
    <list>
    <value>classpath:com/v512</value>
    </list>
    </property>
    <property name="connection">
    <value>classpath:com/v512/indexes</value>
    </property>
    <property name="classMappings">
    <list>
    <value>com.v512.example.model.Product</value>
    </list>
    </property>
    <property name="compassConfiguration"
    ref="annotationConfiguration" /> <property name="compassSettings">
    <props>
    <prop key="compass.transaction.factory">
    org.compass.spring.transaction.SpringSyncTransactionFactory
    </prop>
      <prop key="compass.engine.analyzer.MMAnalyzer.CustomAnalyzer">net.paoding.analysis.analyzer.PaodingAnalyzer </prop>
    </props>
    </property> <property name="transactionManager" ref="transactionManager" />
    </bean>
    <bean id="hibernateGpsDevice"
    class="org.compass.gps.device.hibernate.HibernateGpsDevice">
    <property name="name">
    <value>hibernateDevice</value>
    </property>
    <property name="sessionFactory" ref="sessionFactory" />
    <property name="mirrorDataChanges">
    <value>true</value>
    </property>
    </bean>
    <!-- 鍚屾鏇存柊绱㈠紩 -->
    <bean id="compassGps" class="org.compass.gps.impl.SingleCompassGps"
    init-method="start" destroy-method="stop">
    <property name="compass" ref="compass" />
    <property name="gpsDevices">
    <lst>
    <bean
    class="org.compass.spring.device.SpringSyncTransactionGpsDeviceWrapper">
    <property name="gpsDevice" ref="hibernateGpsDevice" />
    </bean>
    </list>
    </property>
    </bean>
    <bean id="compassTemplate"
    class="org.compass.core.CompassTemplate">
    <property name="compass" ref="compass" />
    </bean> <!-- 瀹氭椂閲嶅缓绱㈠紩(鍒╃敤quartz)鎴栭殢Spring ApplicationContext鍚姩鑰岄噸寤虹储寮?
    <bean id="compassIndexBuilder"
    class="com.v512.example.service.impl.CompassIndexBuilder"
    >
    <property name="compassGps" ref="compassGps" />
    <property name="buildIndex" value="true" />
    <property name="lazyTime" value="10" />
    </bean>
    -->

    <!--鏂板銆愬姛鑳芥暣娴嬭瘯杩囥?beign > 鑷姩闅廠pring ApplicationContext鍚姩鑰岄噸寤虹储寮?-->
    <!-- 鍙傝?璧勬枡锛歨ttp://jiangyingshan.javaeye.com/blog/89860 -->
    <bean id="compassIndexBuilder"
    class="com.v512.example.service.impl.CompassIndexBuilder" lazy-init="false">
    <property name="compassGps">
    <ref local="compassGps" />
    </property>
    <property name="buildIndex">
    <value>true</value>
    </property>
    <property name="lazyTime">
    <value>10</value>
    </property>
    </bean>
    <!--鏂板銆愬姛鑳芥湭娴嬭瘯杩囥?end > 鑷姩闅廠pring ApplicationContext鍚姩鑰岄噸寤虹储寮?-->
    <!-- 鍚屾鏇存柊绱㈠紩 銆愭鍦ㄦ祴璇曚腑鐨勫姛鑳姐? end -->

    <!-- compass bean config end -->
    <bean id="productDao"
    class="com.v512.example.dao.hibernate.ProductDaoHibernate">
    <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <bean id="productManager"
    class="com.v512.example.service.impl.ProductManagerImpl">
    <property name="productDao" ref="productDao"></property>
    <property name="compassTemplate" ref="compassTemplate"></property>
    </bean> <bean id="productBean" class="com.v512.example.action.ProductAction"
    scope="prototype">
    <property name="productManager" ref="productManager"></property> </bean>
    <!-- 閰嶇疆浜嬪姟绠$悊鍣?-->
    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory">
    <ref ocal="sessionFactory" />
    </property>
    </bean> <!-- 閰嶇疆浜嬪姟鐗规? 锛岄厤缃產dd銆乨elete鍜寀pdate寮?鐨勬柟娉曪紝浜嬪姟浼犳挱鐗规?涓簉equired-->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
    <tx:method name="insert*" propagation="REQUIRED" />
    <tx:method name="delete*" propagation="REQUIRED" />
    <tx:method name="update*" propagation="REQUIRED" />
    <tx:method name="*" read-only="true" />
    </tx:attributes>
    </tx:advice> <!-- 閰嶇疆閭d簺绫荤殑鏂规硶杩涜浜嬪姟绠$悊锛屽綋鍓峜n.com.jobedu.oa.service鍖呬腑鐨勫瓙鍖呫?绫讳腑鎵?湁鏂规硶闇?锛岃繕闇?鍙傝?tx:advice鐨勮缃?-->
    <aop:config>
    <aop:pointcut id="allManagerMethod"
    expression="execution (* com.v512.example.service.*.*(..))" />
    <aop:advisor advice-ref="txAdvice"
    pointcut-ref="allManagerMethod" />
    </aop:config>
    </beans>
      

  3.   

    好像和文件本身的编码有关,我在eclipse开始是utf8的,不行,后来我换成gbk的就可以了
      

  4.   


    我的myeclipse默认就是gbk的啊!甚至测试的java类的编码方式都是gbk的。但是在控制台里面打印出来汉字就是乱码,为什么啊?