远程连接windows 出现disconnect: No valid license available 解决方案
2015-01-15 17:49
471 查看
用.properties文件配制
java Bean代码
package org.beans;
public class HelloBean {
private String helloWorld;
public String getHelloWorld() {
return helloWorld;
}
public void setHelloWorld(String helloWorld) {
this.helloWorld = helloWorld;
}
}
beans-config.properties文件
properties代码
helloBean.class=org.beans.HelloBean
helloBean.helloWorld=welcome
主程序代码
package org.test;
import org.beans.HelloBean;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
public class SpringTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
BeanDefinitionRegistry re=new DefaultListableBeanFactory();
PropertiesBeanDefinitionReader reader=new PropertiesBeanDefinitionReader(re);
//也可以用reader.loadBeanDefinitions(new ClassPathResource("beans-config.properties"));
reader.loadBeanDefinitions(new FileSystemResource("org/properties/beans-config.properties"));
BeanFactory factory=(BeanFactory)re;
HelloBean hello=(HelloBean)factory.getBean("helloBean");
System.out.println(hello.getHelloWorld());
}
}
2、在程序中直接编写程序
java 代码
package org.test;
import org.beans.HelloBean;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
public class springMain {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//设置属性
MutablePropertyValues properties=new MutablePropertyValues();
properties.addPropertyValue("helloWorld","Hello,Weimin");
//设置bean定义
RootBeanDefinition definition=new RootBeanDefinition(HelloBean.class,properties);
//注册bean定义与bean别名
BeanDefinitionRegistry re=new DefaultListableBeanFactory();
re.registerBeanDefinition("helloBean", definition);
BeanFactory factory=(BeanFactory)re;
HelloBean hello=(HelloBean)factory.getBean("helloBean");
System.out.println(hello.getHelloWorld());
}
}
java Bean代码
package org.beans;
public class HelloBean {
private String helloWorld;
public String getHelloWorld() {
return helloWorld;
}
public void setHelloWorld(String helloWorld) {
this.helloWorld = helloWorld;
}
}
beans-config.properties文件
properties代码
helloBean.class=org.beans.HelloBean
helloBean.helloWorld=welcome
主程序代码
package org.test;
import org.beans.HelloBean;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
public class SpringTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
BeanDefinitionRegistry re=new DefaultListableBeanFactory();
PropertiesBeanDefinitionReader reader=new PropertiesBeanDefinitionReader(re);
//也可以用reader.loadBeanDefinitions(new ClassPathResource("beans-config.properties"));
reader.loadBeanDefinitions(new FileSystemResource("org/properties/beans-config.properties"));
BeanFactory factory=(BeanFactory)re;
HelloBean hello=(HelloBean)factory.getBean("helloBean");
System.out.println(hello.getHelloWorld());
}
}
2、在程序中直接编写程序
java 代码
package org.test;
import org.beans.HelloBean;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
public class springMain {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//设置属性
MutablePropertyValues properties=new MutablePropertyValues();
properties.addPropertyValue("helloWorld","Hello,Weimin");
//设置bean定义
RootBeanDefinition definition=new RootBeanDefinition(HelloBean.class,properties);
//注册bean定义与bean别名
BeanDefinitionRegistry re=new DefaultListableBeanFactory();
re.registerBeanDefinition("helloBean", definition);
BeanFactory factory=(BeanFactory)re;
HelloBean hello=(HelloBean)factory.getBean("helloBean");
System.out.println(hello.getHelloWorld());
}
}
相关文章推荐
- vnc viewer 远程连接windows 出现disconnect: No valid license available 解决方案
- Android模拟器下用sipdroid拨打电话出现“No suitable data network available”错误提示的解决方案
- EAS 从远程服务器或本地服务器导入解决方案时,出现无法创建连接到所选的数据中心?
- Windows下启动eclipse出现JRE or JDK must be available in order to run Eclipse.No Java virtual machine was
- Spring Boot使用Feign客户端调用远程服务时出现:timed-out and no fallback available,failed and no fallback available的问题解决
- (含软连接修改的分析) 安装caffe 出现libcurl.so.4: no version information available (required by cmake)
- 电脑远程登陆出现“远程计算机已结束连接”解决方案
- WinCVS提交时出现错误 cvs server: C:/WINDOWS/TEMP/cvs**.tmp: No such file or directory 的解决方案
- 出现No valid crossdomain policy available to allow access
- 解决Windows远程连接mysql出现cannot connect(10038)过程
- Android Studio出现 No service of type Factory available in ProjectScopeServices.的错误解决方案
- Linux远程访问windows时,出现"连接被对端重置"错误
- Ubuntu不能利用ssh进行远程连接的解决方案及其解决过程中出现的问题
- VNC连接Ubuntu14.04 远程桌面出现“No supported authentication methods”错误
- 电脑远程登陆出现“远程计算机已结束连接”解决方案
- 大批量执行webservice出现“无法连接远程服务器”解决方案
- Linux远程访问windows时,出现"连接被对端重置"错误
- Windows上使用远程桌面连接出现’终端服务器超出最大连接允许’解决办法
- Mac远程桌面连接Windows问题,出现“由于账户限制,您无法登陆”
- Android Studio出现 No service of type Factory available in ProjectScopeServices. Error解决方案