我是spring框架的初学者,正在开发一个简单的控制台应用程序,用坐标(x,y)显示3个三角形点。当我尝试启动时,它不会解析来自类路径资源的XML文档。
This is Drawing.java class
package org.test;
导入组织。springframework。上下文应用上下文;导入组织。springframework。上下文支持ClassPathXmlApplicationContext;
公共类绘图{
@SuppressWarnings("resource")
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("Spring.xml");
Triangle triangle = (Triangle) context.getBean("triangle");
triangle.draw();
}
}
这是三角形。java类
package org.test;
public class Triangle {
private Point pointA;
private Point pointB;
private Point pointC;
public Point getPointA() {
return pointA;
}
public void setPointA(Point pointA) {
this.pointA = pointA;
}
public Point getPointB() {
return pointB;
}
public void setPointB(Point pointB) {
this.pointB = pointB;
}
public Point getPointC() {
return pointC;
}
public void setPointC(Point pointC) {
this.pointC = pointC;
}
public void draw(){
System.out.println("PointA = (" +getPointA().getX() + " , " + getPointA().getY() + ")");
System.out.println("PointB = (" +getPointB().getX() + " , " + getPointB().getY() + ")");
System.out.println("PointC = (" +getPointC().getX() + " , " + getPointC().getY() + ")");
}
}
这就是重点。java类
package org.test;
public class Point {
private int x;
private int y;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
这是Spring.xml即XML bean配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "https://www.springframework/dtd/spring-beans-2.0dtd">
<beans>
<bean id="triangle" class="org.test.Triangle">
<property name="pointA" ref="ZeroPoint"/>
<property name="pointB" ref="OnePoint"/>
<property name="pointC" ref="TwoSPoint"/>
</bean>
<bean id="ZeropPoint" class="org.test.Point">
<property name="x" value="0.0"/>
<property name="y" value="0.0"/>
</bean>
<bean id="OnePoint" class="org.test.Point">
<property name="x" value="1.0"/>
<property name="y" value="1.0"/>
</bean>
<bean id="TwoPoint" class="org.test.Point">
<property name="x" value="2.0"/>
<property name="y" value="2.0"/>
</bean>
当我尝试启动此控制台应用程序时,出现以下错误:
Sep 04, 2015 10:19:56 AM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1980630: startup date [Fri Sep 04 10:19:56 PKT 2015]; root of context hierarchy
2015年9月4日上午10:19:56组织。springframework。豆。工厂xml。XmlBeanDefinitionReader加载BeanDefinitions
INFO: Loading XML bean definitions from class path resource [Spring.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [Spring.xml]; nested exception is java.net.UnknownHostException: www.springframework
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:410)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:252)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:452)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at org.test.Drawing.main(Drawing.java:11)
Caused by: java.net.UnknownHostException: www.springframework
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.security.ssl.SSLSocketImpl.connect(Unknown Source)
at sun.security.ssl.BaseSSLSocketImpl.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:76)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:429)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
... 14 more
将spring模式和命名空间添加到beans元素,如下所示:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
完全删除DOCTYPE
。
我有一个使用Spring mvc和Spring Security Eclipse Maven web项目。当我真的启动它时,它没有成功地初始化上下文: 更多详情如下: 这是我的 这是我的 我的问题是,当我启动应用程序时,我会出现类似的错误 它说它找不到但是我没有把它放进中,我的配置文件是
问题内容: 是否有API可以获取类路径资源(例如,我将从中获得的资源)?理想情况下,我想将新的API与类路径资源一起使用。 问题答案: 这对我有用:
是否有API来获取类路径资源(例如,我从)作为获取的类路径资源?理想情况下,我希望使用带有类路径资源的新的API。
上面是我的程序,错误显示为: 可能的问题是什么?请帮忙,因为我是新来的 我面临着同样的问题,我该如何解决?
我的Spring microservices原型应用程序无法使用以下消息启动: 应用程序依赖项如下所示: 我假设data-jpa和h2都是数据源附带的。我之前有过类似的组合,没有这个问题。我想这个问题可以通过在其中一个依赖项中排除数据源来解决。经过网上搜索,我还没有找到它是如何工作的。 有什么建议吗?
我有这个错误,我不知道它可能是什么,我留下了一些项目类 xml: 应用Context.xml: Principal.java 错误: SLF4J:未能加载类“org.SLF4J.impl.StaticLoggerBinder”。SLF4J:默认为无操作(NOP)记录器实现SLF4J:请参阅http://www.slf4j.org/codes.html#StaticLoggerBinder了解更多细