Java Tutorial/Spring/ClassPathResource

Материал из Java эксперт
Перейти к: навигация, поиск

Class Path Resource

File: context.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.xsd">
    <bean id="logging" class="LoggingBean"/>
</beans>





Load configuration file with ClassPathResource

File: context.xml



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
   <bean id="dataSource"
         class="org.springframework.jdbc.datasource.DriverManagerDataSource">
   <property name="driverClassName">
       <value>sun.jdbc.odbc.JdbcOdbcDriver</value>
   </property>
   <property name="url">
       <value>jdbc:odbc:test</value>
   </property>
   <property name="username">
       <value>root</value>
   </property>
   <property name="password">
       <value>sql</value>
   </property>
   </bean>
   <bean id="datacon" class="Dataconimpl">
      <property name="dataSource"><ref local="dataSource"/></property>
   </bean>
</beans>





Spring Class Path Resource Demo

File: hello.java



public interface hello
{
      public String sayhello(String a);
}