Attention_1Dark |
关于
JAVA 框架-Spring-IOC/DI 的提问
Cannot resolve property 'name'这是什么问题呀,name一直是红的
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <bean name="c" class="com.how2java.pojo.Category"> <property name="name" value="category 1" /> </bean> </beans> |
yexin |
关于
JAVA 框架-Spring-IOC/DI 的提问
idea创建的项目没有lib文件夹,那lib.rar包应该放在哪里
|
Huishi |
关于
JAVA 框架-Spring-IOC/DI 的提问
Error occurred during initialization of boot layer java.lang.module.ResolutionException: Modules commons.logging.api and commons.logging export package org.apache.commons.logging.impl to module org.springframework.instrument
|
FARO_Z |
关于
JAVA 框架-Spring-IOC/DI 的提问
一定要把applicationContext.xml放在resources目录里面,不然会显示applicationContext.xml找不到 并且 new ClassPathXmlApplicationContext(); 里不要填src/main/resources/applicationContext.xml , 只要填写"applicationContext.xml"就可以了
![]() |
菜鸟_何 |
关于
JAVA 框架-Spring-IOC/DI 的提问
作业
<?xml version="1.0" encoding="UTF-8"?> <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"> <!-- 将对象的创建交给spring管理,id为这个对象的唯一标识,class为被创建对象的全限定路径--> <bean id="product" class="com.atspring.domain.Product"> <!--property意为属性,表示此处填写实体类的属性相关信息。name为属性名,value为未属性赋值--> <property name="id" value="1"></property> <property name="name" value="product"></property> </bean> </beans> public class test { public static void main(String[] args) { //-----使用spring的IOC方式创建product对象 //读取配置文件bean获取context对象 ApplicationContext context=new ClassPathXmlApplicationContext("bean.xml"); //经由context对象创建实例对象 Product product = context.getBean("product", Product.class); System.out.println(product.getName()); } } |
陈渣渣 |
关于
JAVA 框架-Spring-IOC/DI 的提问
(用的idea)下面这是异常,说的就是bean初始化失败,但是我的代码真的没错,网上搜了很多视频也都是一样写的,当我把配置文件唯一一行<property name="name" value="category 1"/>删掉时候,就不报错了 可是这没意义,添上就报初始化失败,怎么回事,我看别人都没这问题。。。pom中导入了spring-core、context和beans 警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'c' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: 'org.springframework.core.MethodParameter org.springframework.core.MethodParameter.withContainingClass(java.lang.Class)' Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'c' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: 'org.springframework.core.MethodParameter org.springframework.core.MethodParameter.withContainingClass(java.lang.Class)' Caused by: java.lang.NoSuchMethodError: 'org.springframework.core.MethodParameter org.springframework.core.MethodParameter.withContainingClass(java.lang.Class)'
|
java小白126 |
关于
JAVA 框架-Spring-IOC/DI 的提问
交作业 五月 04, 2020 1:45:32 下午 org.springframework.context.support.AbstractApplicationContext prepareRefresh 信息: Refreshing org[email protected]506c589e: startup date [Mon May 04 13:45:32 CST 2020]; root of context hierarchy 五月 04, 2020 1:45:32 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definitions from class path resource [applicationContext.xml] 五月 04, 2020 1:45:32 下午 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons 信息: Pre-instantiating singletons in org.s[email protected]57829d67: defining beans [c,p]; root of factory hierarchy product 1
package com.how2java.test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.how2java.pojo.Product; public class TestSpring { public static void main(String[] args) { ApplicationContext context=new ClassPathXmlApplicationContext(new String[] {"applicationContext.xml"}); Product p=(Product) context.getBean("p"); System.out.println(p.getName()); } } <?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <bean name="c" class="com.how2java.pojo.Category"> <property name="name" value="category 1" /> </bean> <bean name="p" class="com.how2java.pojo.Product"> <property name="name" value="product 1" /> </bean> </beans> |
<bean name="p" class="com.how2java.pojo.Product"> <property name="name" value="Product 1"/> </bean> package com.how2java.test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.how2java.pojo.Product; public class TestProudct { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "applicationContext.xml" }); Product p = (Product) context.getBean("p"); System.out.println(p.getName()); } }
package com.hyinghua.pojo; public class Product { private String name; private int age; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } } <bean id="p" class="com.hyinghua.pojo.Product"> <property name="name" value="Produc 2"></property> </bean> public class TestSpring { public static void main(String[] args){ ApplicationContext ac =new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml"}); Category bean =(Category) ac.getBean("c"); Product bean2 = (Product)ac.getBean("p"); System.out.println(bean.getName()); System.out.println(bean2.getName()); } }
五月 31, 2020 8:56:18 下午 org.springframework.context.support.AbstractApplicationContext prepareRefresh 信息: Refreshing org[email protected]6d62f58e: startup date [Sun May 31 20:56:18 CST 2020]; root of context hierarchy 五月 31, 2020 8:56:18 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definitions from class path resource [applicationContext.xml] 五月 31, 2020 8:56:19 下午 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons 信息: Pre-instantiating singletons in org.s[email protected]953235f: defining beans [c,p]; root of factory hierarchy category 1 product 1
疯狂的兔子 |
关于
JAVA 框架-Spring-IOC/DI 的提问
哪位大佬帮我看看我这是什么问题 代码应该没问题 感觉是配置问题
![]() |
阔爱的小兔 |
关于
JAVA 框架-Spring-IOC/DI 的提问
ApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "applicationContext.xml" }); 这一行代码何解,希望解惑
|
早安喵 |
关于
JAVA 框架-Spring-IOC/DI -新建项目 的提问
java project类型 这里是不是有误呀?不应该是java动态网页项目么?不然没有后面提到的lib文件夹的。。。
|
爱吃猫的鱼 |
关于
JAVA 框架-Spring-IOC/DI 的提问
package test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import pojo.Category; import pojo.Product; public class TestSpring { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "applicationContext.xml" }); Category c = (Category) context.getBean("c"); Product a = (Product) context.getBean("b"); System.out.println(c.getName()); System.out.println(a.getName()); } }
|
铁锅炖猪脚 |
关于
JAVA 框架-Spring-IOC/DI -练习 的提问
我是在玩修仙游戏吗 这也太玄学了吧? 开始报错看都看不懂, 重新导入更换jdk版本 问题变为 错误: 找不到或无法加载主类 com.how2java.TestSpring 然后一直这样,然后看springtest名字不舒服,修改为dd(弟弟), 运行成功了? 啥道理? 换个名字就可以了 是我以前取过这个名字吧?
|
铁锅炖猪脚 |
关于
JAVA 框架-Spring-IOC/DI -练习 的提问
这个lib包适配的jdk版本是什么 直接下载的运行出现 错误: 找不到或无法加载主类
|
Study_ |
为什么要用数组接收??是有什么特殊地方嘛?
ApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "applicationContext.xml" }); Category c = (Category) context.getBean("c"); |
gump777 |
关于
JAVA 框架-Spring-IOC/DI 的提问
没有IDEA版本的吗
|
pjj |
关于
JAVA 框架-Spring-IOC/DI 的提问
十月 25, 2019 12:16:36 下午 org.springframework.context.support.AbstractApplicationContext prepareRefresh 信息: Refreshing org[email protected]1a86f2f1: startup date [Fri Oct 25 12:16:36 CST 2019]; root of context hierarchy 十月 25, 2019 12:16:36 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definitions from class path resource [applicationContext.xml] 十月 25, 2019 12:16:36 下午 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons 信息: Pre-instantiating singletons in org.s[email protected]340f438e: defining beans [c]; root of factory hierarchy null
![]() |
一叶秋梦 |
关于
JAVA 框架-Spring-IOC/DI -练习 的提问
将spring.rar解压后用记事本打开 .project 配置文件 修改最上面的 name ,改成spring2或者其他就可以了 不要与eclipse中的项目重名就OK了
|
一叶秋梦 |
<bean name="c" class="com.how2java.pojo.Category"> 上面的"com.how2java.pojo是什么东西 运行时需要更改 吗?
<bean name="c" class="com.how2java.pojo.Category"> <property name="name" value="category 1" /> </bean> 十月 24, 2019 9:45:51 上午 org.springframework.context.support.AbstractApplicationContext prepareRefresh 信息: Refreshing org[email protected]b07fd3: startup date [Thu Oct 24 09:45:51 CST 2019]; root of context hierarchy 十月 24, 2019 9:45:52 上午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definitions from class path resource [applicationContext.xml] 十月 24, 2019 9:45:52 上午 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons 信息: Pre-instantiating singletons in org.s[email protected]1829d67: defining beans [c]; root of factory hierarchy 十月 24, 2019 9:45:52 上午 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons 信息: Destroying singletons in org.s[email protected]1829d67: defining beans [c]; root of factory hierarchy Exception in thread "main" org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.how2java.pojo.Category] for bean with name 'c' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: com.how2java.pojo.Category at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1254) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:576) at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1323) at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:889) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93) at spring.TestSpring.main(TestSpring.java:11) Caused by: java.lang.ClassNotFoundException: com.how2java.pojo.Category 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 java.lang.ClassLoader.loadClass(ClassLoader.java:357) at org.springframework.util.ClassUtils.forName(ClassUtils.java:257) at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:408) at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1275) at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1246) ... 9 more |
loksjhon |
关于
JAVA 框架-Spring-IOC/DI 的提问
新手,请问第七步怎么做??
|
zichengno1 |
关于
JAVA 框架-Spring-IOC/DI 的提问
真心希望站长能把每一步实在做什么讲解一下,目前这样开头写一段综述,然后就开始跑代码,复制代码的过程真的让人摸不着头脑,到最后只会机械模仿
|
小孤心 |
关于
JAVA 框架-Spring-IOC/DI 的提问
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <bean name="c" class="com.how2java.pojo.Category"> <property name="name" value="category 1" /> </bean> <bean name="p" class="com.how2java.pojo.Product"> <property name="name" value="product 1" /> </bean> </beans>
![]() package com.how2java.pojo; public class Product { private int id; private String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } package com.how2java.test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.how2java.pojo.Category; import com.how2java.pojo.Product; public class TestSpring { public static void main(String[] args){ /*ApplicationContext context=new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml"}); Category c=(Category)context.getBean("c"); System.out.println(c.getName());*/ ApplicationContext context=new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml"}); Product p=(Product)context.getBean("p"); System.out.println(p.getName()); } } |
MercyDou |
为什么我直接拷贝jar包到项目里面的lib就不能用,之前学struts框架时候我直接拷贝就能用了呀
|
IAmBestHandsome |
关于
JAVA 框架-Spring-IOC/DI 的提问
Spring中 如何创建10个对象,创建对象之前都要在配置文件里给对象赋值吗?
|
xianzhe |
关于
JAVA 框架-Spring-IOC/DI 的提问
不论我怎么做这些spring的包就好像完全不存在一样,只能在文件管理器看到,eclipse的侧面板里lib文件夹里也能看到,就是导入不了
|
LCJjjj |
关于
JAVA 框架-Spring-IOC/DI 的提问
我这样写也能成功获取到容器,请问这两者有什么区别吗
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); |
liuwei981014 |
关于
JAVA 框架-Spring-IOC/DI 的提问
跟着站长学挺简单的
package pojo; public class Product { private int id; private String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } <bean name="c" class="pojo.Category"> <property name="name" value="category 1" /> </bean> <bean name="p" class="pojo.Product"> <property name="name" value="product 1" /> </bean> public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "applicationContext.xml" }); Category c = (Category) context.getBean("c"); Product p=(Product) context.getBean("p"); System.out.println("通过IOC方式获取分类对象的名字:"+c.getName()); System.out.println("通过IOC方式获取产品对象的名字"+p.getName()); } |
酒味苹果 |
关于
JAVA 框架-Spring-IOC/DI 的提问
<bean name="c" class="pojo.Category"> <property name="name" value="category 1" /> </bean> 一开始我把项目名字也加上去了 class="TestSpring.pojo.Category" 然后一直报找不到类的错误。。 蠢死了、、
<bean name="c" class="pojo.Category"> <property name="name" value="category 1" /> </bean> |
zyp124 |
关于
JAVA 框架-Spring-IOC/DI -导入包 的提问
ioc就是由spring来管理
<property name="name" value="product 1"></property> </bean> </beans> package com.how2java.pojo; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class TestSpring { public static void main(String[] args){ ApplicationContext context=new ClassPathXmlApplicationContext( new String[]{"applicationContext.xml"}); Category c=(Category)context.getBean("c"); System.out.println(c.getName()); } } |
qwer123qw001 |
关于
JAVA 框架-Spring-IOC/DI -新建项目 的提问
在哪里添加spring项目,希望更具体
|
Alex_o |
关于
JAVA 框架-Spring-IOC/DI 的提问
1、提示不支持1.5的话要去设置里边改(Build,Execution,Deployment → Compiler → Java Compiler → Target bytecode version) 2、提示找不到 applicationContext.xml 的请将 applicationContext.xml 放到 resources 目录下(一般是maven项目才会出现这种问题)
|
雷大大的小跟班 |
关于
JAVA 框架-Spring-IOC/DI 的提问
交作业
<bean name = "p" class = " com.how2java.pojo.Category"> <property name="name" value = "Product"/> </bean> ApplicationContext context1 = new ClassPathXmlApplicationContext(new String []{"applicationContext.xml"}); Category att = (Category) context1.getBean("p"); System.out.println(att.getName()); |
瞎搞初学者 |
关于
JAVA 框架-Spring-IOC/DI 的提问
我发现这样居然也可以用,大佬看到后解释一下
applicationContext.xml <bean name="p" class="com.how2java.pojo.Product"> <property name="pname" value="product 1" /> </bean> Product.java package com.how2java.pojo; public class Product { public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setPname(String nameeeee) { this.name = nameeeee; } private int id; private String name; } TestSpring.java public class TestSpring { public static void main(String args[]) { ApplicationContext context = new ClassPathXmlApplicationContext( new String[] {"applicationContext.xml"}); Product p =(Product) context.getBean("p"); System.out.println(p.getName()); } } |
Destroying singletons in org.s[email protected]4411d970: defining beans [c,p]; root of factory hierarchy Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'p' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'name' of bean class [com.youcheng.pojo.Product]: Bean property 'name' is not writable or has an invalid setter method. Did you mean 'PName'?
棱镜 |
关于
JAVA 框架-Spring-IOC/DI 的提问
结合 public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "applicationContext.xml" }); Category c = (Category) context.getBean("c"); System.out.println(c.getName()); } 和 <bean name="c" class="com.how2java.pojo.Category"> <property name="name" value="category 1" /> </bean> 1、在main方法中,把 applicationContext.xml 中的内容读到 context里, 2、context.getBean("c") 就是获取context 中名称为 c 的 bean节点 的内容 ,该内容即是类com.how2java.pojo.Category 实例化出的一个对象,此对象的name属性的值是category 1
public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "applicationContext.xml" }); Category c = (Category) context.getBean("c"); System.out.println(c.getName()); } ====================================================== <bean name="c" class="com.how2java.pojo.Category"> <property name="name" value="category 1" /> </bean> |
XHXH |
关于
JAVA 框架-Spring-IOC/DI 的提问
亲切的lol没了,还以为是5个Hero弄出一个Team呢,没想到最终还是变得和那些晦涩难懂的教程一样。 用一堆名词没法直白的说明spring的作用,也没有讲解applicationContext的作用,applicationContext的结点写法都没有,这个spring的教程该不会是找临时工写的?
|
Java小白进阶 |
关于
JAVA 框架-Spring-IOC/DI -原理图 的提问
博客地址:https://www.cnblogs.com/bencoper/ Spring系列出了6篇文章欢迎各位学友指点大多都是在问答区找到的彩蛋
|
Java小白进阶 |
学习方法:不了解多看一下学友们的提问和站长的回答以及很多大佬给的博客地址 刚开始我也是一脸懵逼的过Spring多查资料,在提问栏中有很多博客文章的推荐点进去看一下差不多应该都能懂大概意思 博客地址:https://www.cnblogs.com/bencoper/ Spring系列出了6篇.文章中提到的推荐资料都是在问答区找的彩蛋很感谢学友们的提供
|
lsh223 |
关于
JAVA 框架-Spring-IOC/DI 的提问
用下载下来的spring可以运行 但是自己编写的时候不能运行 是导入jar包的问题吗?只能导入moudlepath里面,和这个有关系吗?
![]() |
hu0123456789 |
关于
JAVA 框架-Spring-IOC/DI 的提问
在product 作业中,当我把变量名 name 改成pname时,运行就会报错?
applicationContext.xml <bean name="p" class="com.how2java.pojo.Product"> <property name="pname" value="product 1" /> </bean> Product.java package com.how2java.pojo; public class Product { public int getId() { return id; } public void setId(int id) { this.id = id; } public String getPName() { return pname; } public void setName(String pname) { this.pname = pname; } private int id; private String pname; } TestSpring.java public class TestSpring { public static void main(String args[]) { ApplicationContext context = new ClassPathXmlApplicationContext( new String[] {"applicationContext.xml"}); Product p =(Product) context.getBean("p"); System.out.println(p.getPName()); } } Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'p' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'pname' of bean class [com.how2java.pojo.Product]: Bean property 'pname' is not writable or has an invalid setter method. Did you mean 'name'? |
我发现这样居然也可以用,大佬看到后解释一下 applicationContext.xml <bean name="p" class="com.how2java.pojo.Product"> <property name="pname" value="product 1" /> </bean> Product.java package com.how2java.pojo; public class Product { public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setPname(String nameeeee) { this.name = nameeeee; } private int id; private String name; } TestSpring.java public class TestSpring { public static void main(String args[]) { ApplicationContext context = new ClassPathXmlApplicationContext( new String[] {"applicationContext.xml"}); Product p =(Product) context.getBean("p"); System.out.println(p.getName()); } }
getPname setPname
e1se |
关于
JAVA 框架-Spring-IOC/DI 的提问
这个怎么处理,也没导入楼下说的那个jar包
错误: 在类 com.how2java.test.TestSpring 中找不到 main 方法, 请将 main 方法定义为: public static void main(String[] args) 否则 JavaFX 应用程序类必须扩展javafx.application.Application |
public class TestSpring { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "applicationContext.xml" }); Category c = (Category) context.getBean("c"); System.out.println(c.getName()); } }
未保存吧
命运99 |
关于
JAVA 框架-Spring-IOC/DI 的提问
就是不知道运行是怎么运行的,该run on sever 还是 java application
|
陈彦祖 |
想请问下beans中配置的地址那么多要在哪里复制过来
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <bean name="c" class="com.how2java.pojo.Category"> <property name="name" value="category 1" /> </bean> </beans> |
摘一朵沐浴花 |
关于
JAVA 框架-Spring-IOC/DI 的提问
错误: 无法初始化主类 spring.TestSpring 原因: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
|
now2iava |
关于
JAVA 框架-Spring-IOC/DI 的提问
文件结构不一样啊,java project还多了个pom.xml还有很多文件夹,难道是我的eclipse不一样?
|
pom.xml 是用了maven来管理项目。这比传统手动导包方便很多
1093948533 |
关于
JAVA 框架-Spring-IOC/DI 的提问
为什么我将包复制到lib文件夹后,eclipse工程中没有这些包,也没办法导入。
|
Qw1413139726 |
关于
JAVA 框架-Spring-IOC/DI 的提问
作业提交
package pojo; public class Product { private int id; private String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } package test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import pojo.Product; public class Test { public static void main(String[] args) { ApplicationContext ac=new ClassPathXmlApplicationContext(new String[] {"applicationContext.xml"}); Product p= (Product) ac.getBean("p"); System.out.println(p.getName()); System.out.println(p.getId()); } } <bean name="p" class="pojo.Product"> <property name="id" value="999999999"></property> <property name="name" value="崩山裂地斩"></property> |
septdays |
关于
JAVA 框架-Spring-IOC/DI -练习 的提问
能不能在xml文件中用<context:componet-scan base-package="com.how2java.pojo"/> 来代替bean的设置呢
|
Hasaky |
关于
JAVA 框架-Spring-IOC/DI 的提问
这样?
package com.how2java.pojo; public class Product { int id; String name; double price; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } } Product p=(Product)context.getBean("p"); System.out.println("Name: "+p.getName()); <bean name="p" class="com.how2java.pojo.Product"> <property name="name" value="product 1" /> </bean> |
CharlesTrump |
关于
JAVA 框架-Spring-IOC/DI 的提问
你好,请问下了项目,也解压了,然后怎么打开运行呢?
|
dr13986840762 |
关于
JAVA 框架-Spring-IOC/DI 的提问
按正常代码输入,运行后出现异常
Exception in thread "main" org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.how2java.pojo.Category] for bean with name 'c' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: com.how2java.pojo.Category at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1254) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:576) at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1323) at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:889) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93) at spring.test.TestSpring.main(TestSpring.java:11) Caused by: java.lang.ClassNotFoundException: com.how2java.pojo.Category 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 java.lang.ClassLoader.loadClass(ClassLoader.java:357) at org.springframework.util.ClassUtils.forName(ClassUtils.java:257) at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:408) at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1275) at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1246) ... 9 more |
达布尔Double |
关于
JAVA 框架-Spring-IOC/DI 的提问
类的成员变量只能小写吗?我在写代码时用的大写,然后在写XML配置的时候出错,显示:找不到
|
zxy19890418 |
关于
JAVA 框架-Spring-IOC/DI 的提问
最后面的那个category没有出来
![]() Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243) 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:131) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93) at com.how2java.test.TestSpring.main(TestSpring.java:11) Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328) ... 13 more |
李哥哥 |
关于
JAVA 框架-Spring-IOC/DI 的提问
我想把两个对象注入。再打印出来。结果只能打印一个。而且程序运行过一次后。不管怎么修改测试类内容,甚至把所以内容删除。它打印的东西都一样。。。
![]() Category c = (Category) context.getBean("c"); Product p = (Product) context.getBean("p"); System.out.println(c.getName()); System.out.println(p.getName()); |
村雨 |
关于
JAVA 框架-Spring-IOC/DI 的提问
比如说在写注解@Component注解时,每次都要手打完整的单词,有没有什么插件可以在打出前几个字母时,提示出可以用的选项。
|
tt100 |
关于
JAVA 框架-Spring-IOC/DI 的提问
交作业
<bean id="product" class="cn.how2j.Product"> <property name="id" value="1900238432"></property> <property name="name" value="张三"></property> <property name="age" value="90"></property> </bean> public class Product{ private long id; private String name; private byte age; public void setId(long id){ this.id = id; } public long getId(){ return id; } ..... } public class TestProduct(){ ApplicationContext context = new ClassPathXmlContext } |
tt100 |
关于
JAVA 框架-Spring-IOC/DI 的提问
<bean id="product" class="cn.how2j.Product"> <property name="id" value="1900238432"></property> <property name="name" value="张三"></property> <property name="age" value="90"></property> </bean> public class Product{ private long id; private String name; private byte age; public void setId(long id){ this.id = id; } public long getId(){ return id; } ..... }
|
MJ |
关于
JAVA 框架-Spring-IOC/DI 的提问
id和name都可以加载运行。。。什么区别呢
<bean id="category" class="com.how2java.pojo.Category"> <property name="id" value="1001"></property> <property name="name" value="张三"></property> </bean> <bean name="category" class="com.how2java.pojo.Category"> <property name="id" value="1001"></property> <property name="name" value="张三"></property> </bean> |
MJ |
关于
JAVA 框架-Spring-IOC/DI 的提问
1. ApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "applicationContext.xml" }) 2. ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml"); 3. ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:/*.xml"); 这三个什么区别。。第三个是加载路径下的所有xml吧
|
高飞 |
关于
JAVA 框架-Spring-IOC/DI 的提问
站长大大,你能大概解释一下beans后面的那些url是什么意思吗?为什么要这么写? 谢谢!!!!!!!
|
小浩子 |
关于
JAVA 框架-Spring-IOC/DI -下载包 的提问
请问怎么看spring是哪个版本,本人不太懂,百度说有个包叫 spring.jar。没找到。还有一个问题是:现在主流是spring4.x吗
|
小伍 |
关于
JAVA 框架-Spring-IOC/DI 的提问
IOC一般叫控制反转吧
|
春日家的野穹妹 |
关于
JAVA 框架-Spring-IOC/DI 的提问
按正常代码输入,运行后出现异常
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243) 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:131) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93) at com.test.TestSpring.main(TestSpring.java:14) Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328) ... 13 more |
需要在spring右键——Build path——source面板——Add folder,将你所需要的源代码文件都加载到路径下来,这样项目才能找到源文件,才能编译运行。不成功再交流,这几天我都会上网。
Anodyne |
关于
JAVA 框架-Spring-IOC/DI 的提问
右上角可运行项目在idea中怎么运行起来?
|
btyant |
关于
JAVA 框架-Spring-IOC/DI -pojo 的提问
这段是啥意思
|
<bean name="c" class="com.how2java.pojo.Category"> <property name="name" value="category 1" /> </bean> <bean name="d" class="com.how2java.pojo.Category"> <property name="name" value="category 2" /> </bean>
tt100 |
关于
JAVA 框架-Spring-IOC/DI 的提问
练习--使用IOC的方式,获取一个Product对象
public class Product{ private int id; private String name; private int number; private double price; public void setId(int id) { this.id = id } public int getId() { return id; } public void setName(String name) { this.name = name; } public String getName() { return name; } public void setPrice(double price) { this.price = price; } public double getPrice() { return price; } public void setNumber(String number) { this.number = number } public int getNumber() { return number; } } <xml? version="1.0" encodeing="utf-8" > <beans> <bean id="product" class="Product"> <property name="name" value="HUAWEI ipone"> <property name="number" value="10"> <property name="price" value="9800"> <bean> <beans> public class TestProduct{ ApplicationContext atc = new ClassPathApplicationContext("applicationContext.xml"); Product product = (Product)atc.getBean("product"); product.getName(); product.getPrice(); } |
package test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import pojo.Category; import pojo.Product; public class TestSpring { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "applicationContext.xml" }); Category c = (Category) context.getBean("c"); Product a = (Product) context.getBean("b"); System.out.println(c.getName()); System.out.println(a.getName()); } }
<xml? version="1.0" encodeing="utf-8" > <beans> <bean id="product" class="Product"> <property name="name" value="HUAWEI ipone" /> <property name="number" value="10" /> <property name="price" value="9800" /> <bean> <beans>
<xml? version="1.0" encodeing="utf-8" > <beans> <bean id="product" class="Product"> <property name="name" value="HUAWEI ipone" /> <property name="number" value="10" /> <property name="price" value="9800" /> <bean> <beans>
public class Category { public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public void setNumber(String number) { this.number=number; } public String getNumber() { return number; } private int id; private String name; private String number; } public class TestSpring { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "applicationContext.xml" }); Category c = (Category) context.getBean("c"); System.out.println(c.getName()); c.getNumber(); } } <bean name="c" class="com.how2java.pojo.Category"> <property name="name" value="category 1" /> <property name="number" value="hhh"/> </bean>
public class Product{ private int id; private String name; private int number; private double price; public void setId(int id) { this.id = id } public int getId() { return id; } public void setName(String name) { this.name = name; } public String getName() { return name; } public void setPrice(double price) { this.price = price; } public double getPrice() { return price; } public void setNumber(String number) { this.number = number } public int getNumber() { return number; } } <xml? version="1.0" encodeing="utf-8" > <beans> <bean id="product" class="Product"> <property name="name" value="HUAWEI ipone"> <property name="number" value="10"> <property name="price" value="9800"> <bean> <beans> public class TestProduct{ ApplicationContext atc = new ClassPathApplicationContext("applicationContext.xml"); Product product = (Product)atc.getBean("product"); product.getName(); product.getPrice(); }
tt100 |
关于
JAVA 框架-Spring-IOC/DI 的提问
使用IOC的方式,获取一个Product对象
public class Product{ private int id; private String name; private int number; private double price; public void setId(int id) { this.id = id } public int getId() { return id; } public void setName(String name) { this.name = name; } public String getName() { return name; } public void setPrice(double price) { this.price = price; } public double getPrice() { return price; } public void setNumber(String number) { this.number = number } public int getNumber() { return number; } } <xml? version="1.0" encodeing="utf-8" > <beans> <bean id="product" class="Product"> <property name="name" value="HUAWEI ipone"> <property name="number" value="10"> <property name="price" value="9800"> <bean> <beans> public class TestProduct{ ApplicationContext atc = new ClassPathApplicationContext("applicationContext.xml"); Product product = (Product)atc.getBean("product"); product.getName(); product.getPrice(); } |
tt100 |
关于
JAVA 框架-Spring-IOC/DI 的提问
练习--使用IOC的方式,获取一个Product对象
public class Product{ private int id; private String name; private int number; private double price; public void setId(int id) { this.id = id } public int getId() { return id; } public void setName(String name) { this.name = name; } public String getName() { return name; } public void setPrice(double price) { this.price = price; } public double getPrice() { return price; } public void setNumber(String number) { this.number = number } public int getNumber() { return number; } } <xml? version="1.0" encodeing="utf-8" > <beans> <bean id="product" class="Product"> <property name="name" value="HUAWEI ipone"> <property name="number" value="10"> <property name="price" value="9800"> <bean> <beans> public class TestProduct{ ApplicationContext atc = new ClassPathApplicationContext("applicationContext.xml"); Product product = (Product)atc.getBean("product"); product.getName(); product.getPrice(); } |
junxiaoge |
关于
JAVA 框架-Spring-IOC/DI 的提问
如题
|
庄胜文 |
为什么我在“记”里保存的资料都没了?
|
庄胜文 |
ApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "applicationContext.xml" }); Category c = (Category) context.getBean("c");
|
水寒555 |
关于
JAVA 框架-Spring-IOC/DI 的提问
RT,麻烦站长大人了!
|
liu19963600 |
关于
JAVA 框架-Spring-IOC/DI 的提问
通常情况下建包是用bean 还是pojo表示?
|
hui_ca |
关于
JAVA 框架-Spring-IOC/DI -练习 的提问
都按站长说的做了,也没有提示错误,编译运行会弹框A java Exception has occurred怎么解决?
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/how2java/test/TestSpring : Unsupported major.minor version 52.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) at java.net.URLClassLoader.access$100(URLClassLoader.java:71) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482) |
cdfwb |
关于
JAVA 框架-Spring-IOC/DI 的提问
如果按照官网上的例子是应该先给product和category分别先定义一个interface吗,请问先定义一个interface有什么用处?
|
以战止战 |
关于
JAVA 框架-Spring-IOC/DI -导入包 的提问
把jar包导入到项目中后,项目出现红色感叹号
![]() |
Eddiezi |
关于
JAVA 框架-Spring-IOC/DI 的提问
网站提供的jar包共有36个文件,而网站的代码只Build Path了35个,其中一个包名为org.springframework.spring-library-3.1.0.M2.libd不能使用,用了之后就会出现错误: 找不到或无法加载主类 。站长要注意及时更新教程bug啊。不要让我们在这么简单的代码里丢坑了。
|
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>5.1.3.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.1.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>5.1.3.RELEASE</version> </dependency>
wnik |
关于
JAVA 框架-Spring-IOC/DI 的提问
The import org.springframework cannot be resolved 出现这个问题
|
2217268112xkx |
关于
JAVA 框架-Spring-IOC/DI 的提问
我的运行没问题,为啥窗口没有输出,代码和你的是一样的啊?
|
水瓶座的小飞 |
关于
JAVA 框架-Spring-IOC/DI 的提问
我直接按照你的代码跑的呀 没有改动代码 就是你的工程能跑通,我的就不行 很奇怪 有的时候报之前那个错 有的时候报ApplicationContext cannot be resolved to a type 我jar包都导进去了
|
Rengar_Max |
关于
JAVA 框架-Spring-IOC/DI -练习 的提问
com.how2java.pojo.Category里面有getId和setId方法, 但是在applicationContext.xml中没有id这个属性,只有name, 所以id是个默认的属性,还是只是习惯性的?
public int getId() { return id; } public void setId(int id) { this.id = id; } <bean name="c" class="com.how2java.pojo.Category"> <property name="name" value="category 1" /> </bean> |
水瓶座的小飞 |
关于
JAVA 框架-Spring-IOC/DI 的提问
按照步骤做了以后 提示 错误: 找不到或无法加载主类 com.how2java.TestSpring 。请问这是怎么回事儿 我运行右上角的程序就没问题,应该不是环境变量出问题了。
|
罩威 |
关于
JAVA 框架-Spring-IOC/DI -pojo 的提问
准备POJO的具体步骤是什么
|
public class app { private Integer id; private String name; @Override public String toString() { return "app [id=" + id + ", name=" + name + "]"; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public app(Integer id, String name) { super(); this.id = id; this.name = name; } public app() { super(); }
怨不起愿不弃 |
关于
JAVA 框架-Spring-IOC/DI 的提问
站长是这样的,一开始呢,学习你的代码码上去呢,我自己发现run不动。然后搞了一整天,晚上发现是JDK版本问题。我一开始以为跑不动,我就换JDK换到了1.8.最后在报了一个Imported project refers to unknown jdks JAVAse-1.8 。 我给师兄看看了这个,换了1.7的。直接成功都不知道什么问题。在这之前你程序也下载了,但是也是不能成功了。一开始以为是个很特殊的JAR包没下,也以为是环境变量的配置问题。结果都不是。
![]() |
Sink |
关于
JAVA 框架-Spring-IOC/DI 的提问
idea导入为 Java项目,<property name="name" value="category 1" /> ,提示有错“”“Cannot resolve property” ,,,这个是怎么解决呢
<bean name="c" class="com.how2java.pojo.Category"> <property name="name" value="category 1" /> </bean> |
HelloRaven |
关于
JAVA 框架-Spring-IOC/DI 的提问
每次创建实体类的时候能否不用bean.xml,因为如果每次都要创建bean.xml,会不会太麻烦,IOC的注入,实体类中的setters算不算是注入?
|
tomoya |
如题
Category c = (Category) context.getBean("c"); |
<bean name="c" class="com.spring.pojo.Category"> <property name="name" value="category 1"></property> </bean>
勇气 |
关于
JAVA 框架-Spring-IOC/DI 的提问
老师,我要是把applicationContext.xml放到其他路径要怎么修改啊?
|
madarauchiha |
关于
JAVA 框架-Spring-IOC/DI 的提问
src和bin必须有applicationContext.xml
|
Product p = (Product) context.getBean("p"); System.out.println(p.getPrice()); <bean name="p" class="com.how2java.pojo.Product"> <property name="price" value="20yuan" /> </bean>
madarauchiha |
关于
JAVA 框架-Spring-IOC/DI 的提问
src和bin必须有applicationContext.xml
|
嘭嘭 |
关于
JAVA 框架-Spring-IOC/DI -练习 的提问
new ClassPathXmlApplicationContext(
new String[] { "applicationContext.xml" }这怎么理解?重点是 new String[] { "applicationContext.xml" }是什么意思?
ApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "applicationContext.xml" }); |
ApplicationContext context =
new
ClassPathXmlApplicationContext(
"applicationContext.xml"
);
分享如下连接可增加积分,获取50%佣金