您好,我要用 java (NetBeans) 开发 Web 服务,但在获取连接时遇到问题,出现以下错误:
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.net.UnknownHostException: C
Caused by: java.net.UnknownHostException: C
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at sun.net.ftp.impl.FtpClient.doConnect(FtpClient.java:957)
at sun.net.ftp.impl.FtpClient.tryConnect(FtpClient.java:917)
at sun.net.ftp.impl.FtpClient.connect(FtpClient.java:1012)
at sun.net.ftp.impl.FtpClient.connect(FtpClient.java:998)
at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:294)
at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:393)
at org.springframework.core.io.UrlResource.getInputStream(UrlResource.java:103)
at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:179)
at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:158)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(Proper at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:68)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:467)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:334)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:122)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:76)
at com.rsa.ims.components.spring.SimpleApplicationLoader.loadBeanFactory(SimpleApplicationLoader.java:134)
at com.rsa.ims.components.spring.SimpleApplicationLoader.useBeanFactory(SimpleApplicationLoader.java:105)
at com.rsa.command.ConnectionFactory.getSpringBeanTarget(ConnectionFactory.java:183)
at com.rsa.command.ConnectionFactory.getTarget(ConnectionFactory.java:156)
at com.rsa.command.ConnectionFactory.getConnection(ConnectionFactory.java:238)
at com.rsa.command.ConnectionFactory.getConnection(ConnectionFactory.java:281)
at com.arame.rsa.cmdConnection.getConnection(cmdConnection.java:33)
at com.arame.rsa.ApiRsaTest.main(ApiRsaTest.java:49)
Exception in thread "main" java.lang.NullPointerException
at com.arame.rsa.cmdConnection.closeConnection(cmdConnection.java:59)
at com.arame.rsa.ApiRsaTest.main(ApiRsaTest.java:94)
我有 config.properties,其中 URL 和 Context.xml 该文件处理以从文件 config.properties 检索属性,也有 log4j.xml/dtd 所有这些都在我的类路径中。
这是我的con Context.xml
<beans default-lazy-init="true" xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans">
<bean name="PrimaryPropertyPlaceHolderPostProcessor" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="order" value="10"/>
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<property name="location" value="file://C:\\Users\\gerardo.granados\\Documents\\APITest\\build\\classes\\config.properties"/>
<property name="ignoreUnresolvablePlaceholders" value="false"/>
<property name="ignoreResourceNotFound" value="false"/>
</bean>
<bean name="ConnectionInfoProvider"
class="com.rsa.command.PropertiesConnectionInfoProvider"
lazy-init="false">
<property name="propertiesFile" value="config.properties"/>
</bean>
<alias alias="CommandAPIConnection" name="SOAPCommandTargetBasicAuth"/>
<bean name="ClusterTarget" lazy-init="true"
class="com.rsa.command.RemoteCommandTargetFactoryBean">
<property name="providerURL" value="t3s://node1-address,node2-address:7002"/>
<property name="connectionInfoProvider" ref="ConnectionInfoProvider"/>
<property name="targetClass" value="com.rsa.command.EJBRemoteTarget"/>
<property name="cacheable" value="true"/>
</bean>
<bean name="SpecificNodeTarget" lazy-init="true"
class="com.rsa.command.RemoteCommandTargetFactoryBean">
<property name="providerURL" value="t3s://node2-address:7002"/>
<property name="connectionInfoProvider" ref="ConnectionInfoProvider"/>
<property name="targetClass" value="com.rsa.command.EJBRemoteTarget"/>
<property name="cacheable" value="true"/>
<property name="properties">
<props>
<prop key="com.rsa.naming.pin.to.primary.server">true</prop>
</props>
</property>
</bean>
</beans>
有什么建议吗???谢谢
最佳答案
行中:
<property name="location" value="file://C:\\Users\\gerardo.granados\\Documents\\APITest\\build\\classes\\config.properties"/>
删除file:
后面的前两个斜杠。像这样:
<property name="location" value="file:C:\\Users\\gerardo.granados\\Documents\\APITest\\build\\classes\\config.properties"/>
这对我在相关问题上有用。
关于java - 无法加载属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26163316/