我有代码@Inject在一个类中工作但在其他类中没有.这是我的代码:
<?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
">
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"></bean>
<context:component-scan base-package="com.myfashions.services"/>
<context:component-scan base-package="com.myfashions.dao"/>
</beans>
Run Code Online (Sandbox Code Playgroud)
public class SellerRetriever {
@Inject
UserDAO userDAO;
...
...
}
Run Code Online (Sandbox Code Playgroud)
UserDAO类存在于com.myfashions.dao包中.
@Inject在Seller.java中不起作用.有什么理由吗?
任何人都可以解释为什么@Inject对象在使用new运算符初始化类时为null ?
public class A{
@Inject
B b;
...
...
}
Run Code Online (Sandbox Code Playgroud)
当创建上述类的A a = new A();,我得到b的null.有谁能解释为什么?我知道它在Inject A类时有效.但是我想知道为什么它不适用于new运算符.春天做什么?
我们如何在java中打印缓冲图像?我们可以将FileInputStream发送到Print Service,但我需要向它发送缓冲的Image.
FileInputStream fin = new FileInputStream("YOurImageFileName.PNG");
Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null);
job.print(doc, pras);
Run Code Online (Sandbox Code Playgroud)
可能吗?
在这里查看完整的代码.