SpringMVC_v02中的总结(web项目、java项目中引入Config.properties,加载hibernate映射文件的配置的区别)
2015-03-25 15:34
447 查看
SpringMVC_v02中的总结(web项目、java项目中引入Config.properties,加载hibernate映射文件的配置的区别)
1\System.out.println("1-"+new methodInService().getClass().getName()+
"\n2- "+new methodInService().getClass().getSuperclass().getName()+
"\n3- "+methodInService.class+
"\n4- "+methodInService.class.getName()+
"\n5- "+methodInService.class.getResource("")+ 编译后class文件路径
"\n6- "+methodInService.class.getResource("/")+ /class
"\n7- "+methodInService.class.getResource("/com/mvc/action/")+ 切换文件加/
"\n8- "+methodInService.class.getResource("/com/mvc/action/TestAction.class")+
"\n9- "+methodInService.class.getResource("methodInService.class")+
"\n10-"+methodInService.class.getResource("TestAction.class")+ //null
"\n11-"+methodInService.class.getClassLoader().getResource("")+
/class
"\n12-"+methodInService.class.getClassLoader().getResource("com/mvc/action/TestAction.class") 不用加/
);
1-XX.Class.getClassLoader().getResourse("");
类名直接用Class
2-new XX().getClass().getClassLoader.getResourse();
new 的类用getClass()
3-XX.Class.getResourse("/");
1-com.mvc.service.methodInService
2- java.lang.Object
3- class com.mvc.service.methodInService
4- com.mvc.service.methodInService
5- file:/H:/Personal/spmvc_v02/WebRoot/WEB-INF/classes/com/mvc/service/
6- file:/H:/Personal/spmvc_v02/WebRoot/WEB-INF/classes/
7- file:/H:/Personal/spmvc_v02/WebRoot/WEB-INF/classes/com/mvc/action/
8- file:/H:/Personal/spmvc_v02/WebRoot/WEB-INF/classes/com/mvc/action/TestAction.class
9- file:/H:/Personal/spmvc_v02/WebRoot/WEB-INF/classes/com/mvc/service/methodInService.class
10-null
11-file:/H:/Personal/spmvc_v02/WebRoot/WEB-INF/classes/
12-file:/H:/Personal/spmvc_v02/WebRoot/WEB-INF/classes/com/mvc/action/TestAction.class
13-null
14-file:/H:/Personal/spmvc_v02/WebRoot/WEB-INF/classes/
2\bean init-method spring容器加载自动执行
String conf = "applicationContext.xml";
//doinit执行
AbstractApplicationContext ac = new ClassPathXmlApplicationContext(conf);
3\web项目,不是java项目
4\加载Config.properties配置文件
--------------web------------------------
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" id="propertyConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/classes/Config.properties</value>
</list>
</property>
</bean>
--------------web,java------------------------
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" id="propertyConfigurer">
<property name="locations">
<list>
<value>*.properties</value>
</list>
</property>
</bean>
----------------------------------------------------------------
<context:property-placeholder location="classpath*:*.properties"/>
待定(build.xml打好的jar包里执行只能用这种,上面两种执行报错???)
build.xml中都可以用,报错的原因可能是因为spring是3.0.5版本的,但是applicationContext.xml中
最上面引入的是3.1版本的。
因为hibernate映射文件的路径配置错了
-------------------------------------------------------
5、加载Hibernate映射文件
web项目:
<!-- property name="mappingDirectoryLocations">
<list>
<value>classpath:/com/mvc/orm</value>
</list>
</property -->
java项目:
<property name="mappingResources">
<list>
<value>com/mvc/orm/EqpEquipment.hbm.xml</value>
</list>
</property>
java项目
<property name="mappingLocations">
<list>
<value>classpath*:com/test/pojo/*.hbm.xml</value>
</list>
</property>
1\System.out.println("1-"+new methodInService().getClass().getName()+
"\n2- "+new methodInService().getClass().getSuperclass().getName()+
"\n3- "+methodInService.class+
"\n4- "+methodInService.class.getName()+
"\n5- "+methodInService.class.getResource("")+ 编译后class文件路径
"\n6- "+methodInService.class.getResource("/")+ /class
"\n7- "+methodInService.class.getResource("/com/mvc/action/")+ 切换文件加/
"\n8- "+methodInService.class.getResource("/com/mvc/action/TestAction.class")+
"\n9- "+methodInService.class.getResource("methodInService.class")+
"\n10-"+methodInService.class.getResource("TestAction.class")+ //null
"\n11-"+methodInService.class.getClassLoader().getResource("")+
/class
"\n12-"+methodInService.class.getClassLoader().getResource("com/mvc/action/TestAction.class") 不用加/
);
1-XX.Class.getClassLoader().getResourse("");
类名直接用Class
2-new XX().getClass().getClassLoader.getResourse();
new 的类用getClass()
3-XX.Class.getResourse("/");
1-com.mvc.service.methodInService
2- java.lang.Object
3- class com.mvc.service.methodInService
4- com.mvc.service.methodInService
5- file:/H:/Personal/spmvc_v02/WebRoot/WEB-INF/classes/com/mvc/service/
6- file:/H:/Personal/spmvc_v02/WebRoot/WEB-INF/classes/
7- file:/H:/Personal/spmvc_v02/WebRoot/WEB-INF/classes/com/mvc/action/
8- file:/H:/Personal/spmvc_v02/WebRoot/WEB-INF/classes/com/mvc/action/TestAction.class
9- file:/H:/Personal/spmvc_v02/WebRoot/WEB-INF/classes/com/mvc/service/methodInService.class
10-null
11-file:/H:/Personal/spmvc_v02/WebRoot/WEB-INF/classes/
12-file:/H:/Personal/spmvc_v02/WebRoot/WEB-INF/classes/com/mvc/action/TestAction.class
13-null
14-file:/H:/Personal/spmvc_v02/WebRoot/WEB-INF/classes/
2\bean init-method spring容器加载自动执行
String conf = "applicationContext.xml";
//doinit执行
AbstractApplicationContext ac = new ClassPathXmlApplicationContext(conf);
3\web项目,不是java项目
4\加载Config.properties配置文件
--------------web------------------------
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" id="propertyConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/classes/Config.properties</value>
</list>
</property>
</bean>
--------------web,java------------------------
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" id="propertyConfigurer">
<property name="locations">
<list>
<value>*.properties</value>
</list>
</property>
</bean>
----------------------------------------------------------------
<context:property-placeholder location="classpath*:*.properties"/>
待定(build.xml打好的jar包里执行只能用这种,上面两种执行报错???)
build.xml中都可以用,报错的原因可能是因为spring是3.0.5版本的,但是applicationContext.xml中
最上面引入的是3.1版本的。
因为hibernate映射文件的路径配置错了
-------------------------------------------------------
5、加载Hibernate映射文件
web项目:
<!-- property name="mappingDirectoryLocations">
<list>
<value>classpath:/com/mvc/orm</value>
</list>
</property -->
java项目:
<property name="mappingResources">
<list>
<value>com/mvc/orm/EqpEquipment.hbm.xml</value>
</list>
</property>
java项目
<property name="mappingLocations">
<list>
<value>classpath*:com/test/pojo/*.hbm.xml</value>
</list>
</property>
相关文章推荐
- 一个java web项目classpath配置文件加载类
- java web项目启动加载properties属性文件
- 在web项目下引入hibernate配置文件
- 非web java项目部署到linux总结(非打包成jar,配置文件可以随时修改)
- javaWeb项目SpringMVC3.2.1与Mybatis3.0.4整合实例(Mybaits-spring配置文件的几种方式)之一SqlSessionDaoSupport方式
- Java Web项目如何读取.properties配置文件
- java非web应用修改 properties/xml配置文件后,无需重启应用即可生效---自动加载
- Java Web项目加载properties资源文件
- Spring学习总结(20)——Spring加载多个项目properties配置文件问题解决
- SSH项目web.xml文件的常用配置【struts2的过滤器、spring监听器、解决Hibernate延迟加载问题的过滤器、解决中文乱码的过滤器】
- Java的项目(资源或者配置)文件的加载总结
- Spring学习总结(20)——Spring加载多个项目properties配置文件问题解决
- 项目总结SpringMVC+hibernate框架 原理(MVC) 模块配置文件(4)
- 获取java web项目里面所有的properties文件并组装在一起,使用方便,配置简单
- Java Web 项目中的配置文件路径
- asp.net项目中通过Web.config配置文件及文件夹的访问权限!
- 通过web.config文件配置项目中文件夹的访问权限
- 加载配置文件时出错: 对路径 web.config”的访问被拒绝。
- 通过web.config文件配置项目中文件夹的访问权限
- 加载配置文件时出错: 对路径 web.config”的访问被拒绝。