我正在开发一个小型Spring应用程序.我必须将学生信息的详细信息存储在数据库中.我开发了一个SimpleFormController.我使用过NetBeans + Hibernate映射+ Spring.部署项目时,会发生以下错误.
我的spring-config-db-applicationContext.xml如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- Hibernate session factory -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<constructor-arg index="0">
<value>${driverClassName}</value>
</constructor-arg>
<constructor-arg index="1">
<value>${url}</value>
</constructor-arg>
<constructor-arg index="2">
<value>${username}</value>
</constructor-arg>
<constructor-arg index="3">
<value>${password}</value>
</constructor-arg>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<!-- <property name="configLocation">
<value>WEB-INF/classes/hibernate.cfg.xml</value>
</property> -->
<property name="mappingResources" >
<list>
<value>hibernate.cfg.xml</value>
</list>
</property>
<!-- <property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property> -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<!--<prop key="hibernate.hbm2ddl.auto">create</prop>-->
</props>
</property>
</bean>
<bean …Run Code Online (Sandbox Code Playgroud) Hiii ...我想使用getSystemResourceAsStream()将属性文件的内容输入到InputStream类对象中.我已经构建了示例代码.它使用main()方法很好用,但是当我部署项目并在服务器上运行时,无法获取属性文件路径...所以inputstream对象存储空值.
示例代码在这里..
public class ReadPropertyFromFile {
public static Logger logger = Logger.getLogger(ReadPropertyFromFile.class);
public static String readProperty(String fileName, String propertyName) {
String value = null;
try {
//fileName = "api.properties";
//propertyName = "api_loginid";
System.out.println("11111111...In the read proprty file.....");
// ClassLoader loader = ClassLoader.getSystemClassLoader();
InputStream inStream = ClassLoader.getSystemResourceAsStream(fileName);
System.out.println("In the read proprty file.....");
System.out.println("File Name :" + fileName);
System.out.println("instream = "+inStream);
Properties prop = new Properties();
try {
prop.load(inStream);
value = prop.getProperty(propertyName);
} catch (Exception e) {
logger.warn("Error occured while reading …Run Code Online (Sandbox Code Playgroud)