Java类获取Spring的applicationContext.xml文件中的bean
来源:互联网 发布:淘宝买玩具枪犯法吗 编辑:程序博客网 时间:2024/05/22 02:15
public class UtilGetBean { public static Object getBean(String beanName) { ServletContext sc=ServletActionContext.getServletContext(); WebApplicationContext wc=WebApplicationContextUtils.getWebApplicationContext(sc); Object obj= wc.getBean(beanName); return obj; }}
以上工具类,只需传入bean的名称即可获取。
示例:(获取connection连接)
public static Connection getConnection(){Connection conn = null;try {ComboPooledDataSource dataSource = (ComboPooledDataSource)UtilGetBean.getBean("dataSource");conn = dataSource.getConnection();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return conn;}
- Java类获取Spring的applicationContext.xml文件中的bean
- spring获取applicationContext.xml中bean内容
- Java类中加载Spring中的ApplicationContext.xml文件的方式
- Java类中加载Spring中的ApplicationContext.xml文件的方式
- Java类中加载Spring中的ApplicationContext.xml文件的方式
- Spring的applicationContext.xml的bean 说明
- Spring的applicationContext.xml文件
- Spring的applicationContext.xml文件
- Spring的applicationContext.xml文件
- Spring的applicationContext.xml文件
- 普通Java类获取Spring的ApplicationContext
- 普通Java类获取Spring的ApplicationContext
- Java类获取Spring的ApplicationContext
- 普通Java类获取Spring的ApplicationContext
- Java类获取Spring的ApplicationContext
- Java类获取Spring的ApplicationContext
- Spring Bean获取applicationcontext方法
- applicationContext.xml文件如何共引用另一个applicationContext.xml文件中的bean
- EBS常用命令
- Linux下运行window程序的解决方法
- How to create a Java component with Eclipse
- ios开发资料
- socket program error:Socket operation on non-socket
- Java类获取Spring的applicationContext.xml文件中的bean
- 解决【Warning: Cannot modify header information - headers already sent by....】
- linux udev 机制
- linux 删除含特殊字符文件
- sqlserver事务的用法
- Linux下各种压缩文件的解压方法
- 响应式布局插:isotope和masonary
- mysql新建数据库和创建用户的命令
- 【Android 开发教程】AnalogClock和DigitalClock