这是spring配置<?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="${driver}" />
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<property name="initialSize" value="3" />
<property name="maxActive" value="5" />
-->
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/ibatis" />
<property name="username" value="root" />
<property name="password" value="" />
<property name="initialSize" value="3" />
<property name="maxActive" value="5" />
</bean> <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>SqlMapConfig.xml</value>
</property>
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean> <bean id="testDAO" class="com.test.TestDaoImpl">
<property name="sqlMapClient">
<ref bean="sqlMapClient"/>
</property>
</bean></beans>数据库配置文件driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/ibatis
username=root
password=为什么我datasource那个地方的<property name="driverClassName" value="${driver}" />
不能通过美元符来获取,并且报错:不能加载 ${driver},但是直接写路径就可以运行
不知道为什么,我写的数据库配置文件他就读取不到。我用一个测试类,是在控制台输出的查询结果等等。显示正常。
我想是不是没有启动web服务器不能这样搞呢?
求解
<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="${driver}" />
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<property name="initialSize" value="3" />
<property name="maxActive" value="5" />
-->
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/ibatis" />
<property name="username" value="root" />
<property name="password" value="" />
<property name="initialSize" value="3" />
<property name="maxActive" value="5" />
</bean> <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>SqlMapConfig.xml</value>
</property>
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean> <bean id="testDAO" class="com.test.TestDaoImpl">
<property name="sqlMapClient">
<ref bean="sqlMapClient"/>
</property>
</bean></beans>数据库配置文件driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/ibatis
username=root
password=为什么我datasource那个地方的<property name="driverClassName" value="${driver}" />
不能通过美元符来获取,并且报错:不能加载 ${driver},但是直接写路径就可以运行
不知道为什么,我写的数据库配置文件他就读取不到。我用一个测试类,是在控制台输出的查询结果等等。显示正常。
我想是不是没有启动web服务器不能这样搞呢?
求解
解决方案 »
- 怎么防止点击一次按钮触发多次下载事件?
- URI编码与解码的问题
- Eclipse 启动tomcat时报错:java.io.UnsupportedEncodingException: GBK
- AuthenticationFailedException???咋回事?
- jsp 如何处理空格
- 在jsp页面调用bean报错!!!
- 急!急啊,大家行行好,帮帮忙!
- 国际化取值
- 我在编写servlet的时候,出现下面的提示
- Servlet打印的问题?
- 把一个页面里面的所有函数都封装到一个函数里面,另外一个页面怎样通过ajax请求响应它?
- servlet验证用户名和密码问题?不明白 为什么他总是跳过我的if(rs.next)而偏去执行else呢?为啥连个数据库就那么难呢?学习可真不容易
好像叫PropertyPlaceholderConfigurer这个类的配置信息呢?需要定义这个bean,并配置你的配置文件所在地吧,不然spring到哪儿去找${driver}这个东西?
location="classpath:database.properties" />
50分全部给你
<!-- 连接池 -->
<bean id="pool"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://127.0.0.1:3306/routing">
</property>
<property name="username" value="ht"></property>
<property name="password" value="123456"></property>
<!-- 连接池大小 -->
<property name="maxActive" value="5"></property>
<!-- 最多闲置数 -->
<property name="maxIdle" value="3"></property>
<!-- 最大挂起数 -->
<property name="maxWait" value="4"></property>
</bean><!-- ibatis -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource" ref="pool"></property>
<property name="configLocation" value="classpath:sqlMapConfig.xml"></property>
</bean>
<bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient" ref="sqlMapClient"></property>
</bean>
<?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="pool"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://127.0.0.1:3306/routing">
</property>
<property name="username" value="ht"></property>
<property name="password" value="123456"></property>
<!-- 连接池大小 -->
<property name="maxActive" value="5"></property>
<!-- 最多闲置数 -->
<property name="maxIdle" value="3"></property>
<!-- 最大挂起数 -->
<property name="maxWait" value="4"></property>
</bean>
<!-- hibernate session工厂 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="pool"></property>
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- ibatis -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource" ref="pool"></property>
<property name="configLocation" value="classpath:sqlMapConfig.xml"></property>
</bean>
<bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient" ref="sqlMapClient"></property>
</bean>
</beans>