我在访问之前在相同上下文中发布的大量问题后发布了我的查询,遗憾的是,他们都没有解决我的问题。我在春天尝试完整的基于xml的配置,而不使用任何注释。但是一旦我启动应用程序,我就会遇到以下异常。
找不到类[com.kashyap.springboot.xml.JdbcConnectionXML.java] 对于名称为'连接'在类路径资源中定义 [applicationContext.xml中];嵌套异常是 抛出java.lang.ClassNotFoundException: com.kashyap.springboot.xml.JdbcConnectionXML.java
我已经照顾过的事情: -
已经使用默认的公共构造函数定义了类,用于反射所需的实例化(虽然它不是必需的,但是将其用作预防措施)。唉!!!这些都没有奏效。请在下面找到类和xml。
package com.kashyap.springboot.xml;
public class JdbcConnectionXML {
public JdbcConnectionXML(){
System.out.println("JDBC XML Constructor Called");
}
}
package com.kashyap.springboot.xml;
public class PrototypeXMLDAO {
public PrototypeXMLDAO(){
System.out.println("PrototypeXMLDAO Constructor Called");
}
private JdbcConnectionXML connection;
public JdbcConnectionXML getConnection() {
return connection;
}
public void setConnection(JdbcConnectionXML connection) {
this.connection = connection;
}
}
package com.kashyap.springboot.xml;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SpringbootdevApplication {
public static void main(String[] args) {
try (ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");) {
PrototypeXMLDAO pdCDIOne = context.getBean(PrototypeXMLDAO.class);
PrototypeXMLDAO pdCDITwo = context.getBean(PrototypeXMLDAO.class);
System.out.println(pdCDIOne);
System.out.println(pdCDIOne.getConnection());
System.out.println(pdCDITwo);
System.out.println(pdCDITwo.getConnection());
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.kashyap.springboot.xml" />
<bean id="connection" class="com.kashyap.springboot.xml.JdbcConnectionXML">
</bean>
<bean id="prototype" class="com.kashyap.springboot.xml.PrototypeXMLDAO">
<property name="connection" ref="connection"></property>
</bean>
</beans>
控制台上的堆栈跟踪如下: -
线程中的异常&#34; main&#34; org.springframework.beans.factory.CannotLoadBeanClassException:不能 找到类[com.kashyap.springboot.xml.JdbcConnectionXML.java] 豆与名称&#39;连接&#39;在类路径资源中定义 [applicationContext.xml中];嵌套异常是 抛出java.lang.ClassNotFoundException: com.kashyap.springboot.xml.JdbcConnectionXML.java at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1380) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:670) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:637) 在 org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1489) 在 org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1007) 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:739) 在 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) 在 org.springframework.context.support.ClassPathXmlApplicationContext。(ClassPathXmlApplicationContext.java:144) 在 org.springframework.context.support.ClassPathXmlApplicationContext。(ClassPathXmlApplicationContext.java:85) 在 com.kashyap.springboot.xml.SpringbootdevApplication.main(SpringbootdevApplication.java:13) 引起:java.lang.ClassNotFoundException: com.kashyap.springboot.xml.JdbcConnectionXML.java at java.net.URLClassLoader.findClass(URLClassLoader.java:381)at java.lang.ClassLoader.loadClass(ClassLoader.java:424)at sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:331)at at java.lang.ClassLoader.loadClass(ClassLoader.java:357)at org.springframework.util.ClassUtils.forName(ClassUtils.java:255)at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:418) 在 org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1428) 在 org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1372) ......还有10个
如果需要,我也会发布pom.xml。任何形式的帮助都将受到高度赞赏。