java拍照java 扫描注解搜索问题

spring 2.5 自动扫描bean的问题 - ITeye问答
1.applicationContext.xml:
在applicationContext.xml配置了&context:component-scan base-package="aa" /&
2.AA.java内容:
import java.io.PrintS
import org.springframework.context.support.ClassPathXmlApplicationC
public class AA{
& public static void main(String[] args){
&&& BB bs = (BB)new ClassPathXmlApplicationContext(new String[] { "applicationContext.xml"}).getBean("bb");
&&& System.out.println("@@@" + bs.a);
& }
}
3.BB.java内容:
import org.springframework.context.annotation.S
import org.springframework.stereotype.C
@Component("bb")
@Scope("prototype")
public class BB{
& String a = "ssssssssss";
}
4.将其打成jar包运行报错:
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitio
nException: No bean named 'bb' is defined
&&&&&&& at org.springframework.beans.factory.support.DefaultListableBeanFactory.
getBeanDefinition(DefaultListableBeanFactory.java:387)
&&&&&&& at org.springframework.beans.factory.support.AbstractBeanFactory.getMerg
edLocalBeanDefinition(AbstractBeanFactory.java:968)
&&&&&&& at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBe
an(AbstractBeanFactory.java:246)
&&&&&&& at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:185)
&&&&&&& at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:164)
&&&&&&& at org.springframework.context.support.AbstractApplicationContext.getBea
n(AbstractApplicationContext.java:881)
&&&&&&& at aa.AA.main(AA.java:11)
5.在eclipse中运行一切正常,但打成jar后就报错了,将applicationContext.xml中加上&bean id="bb" class="aa.BB" /&
打成jar后运行就正常了
请问各位大侠们是不是打成jar后spring的自动扫描bean的功能就失效了还是我哪里配置错误了????谢谢各位大哥的指点!!
目前还没有答案
已解决问题
未解决问题15:13 提问
java集合jsp 在手机上html5调用摄像头扫描二维码,小白跪求啊!大神在哪里
最近一个项目需要做在手机上的浏览器中具有扫描二维码的功能,自己看了很多网上的demo,但都没有jsp和java结合的,很多是和
php结合的,或者是安卓的,求教啊,大神在哪里。救救小白吧,去年就在学习怎么做,但到现在还是没有出来,跪求大神。
按赞数排序
。。。。。。。。。。。。。怎么办?
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐用Java直接从扫描仪获得扫描数据,然后上载到服务器上,这样的程序需要利用那些知识点(有关Java)?_百度知道
用Java直接从扫描仪获得扫描数据,然后上载到服务器上,这样的程序需要利用那些知识点(有关Java)?
我想用Java开发一个程序,直接从扫描仪获得扫描数据,然后上载到服务器上,这样的程序需要利用那些知识点(有关Java)
我有更好的答案
package edu.ctgu.JT import java.awt.BorderL import java.awt.C import java.awt.D import java.awt.G import java.awt.R import java.awt.T import java.awt.event.ActionE import java.awt.event.ActionL import java.awt.event.WindowA import java.awt.event.WindowE import java.awt.event.WindowL import java.awt.image.BufferedI import java.io.F import java.io.FileInputS import javax.swing.JB import javax.swing.JComboB import javax.swing.JF import javax.swing.JP import javax.swing.JScrollP import javax.swing.JToolB import javax.swing.SwingU import com.sun.image.codec.jpeg.JPEGC import com.sun.image.codec.jpeg.JPEGImageD import edu.ctgu.twain.JT /* 这是显示扫描图片的frame */ public class JTwacker extends JFrame { class JPEGPanel extends JPanel { /** Image for the inner class */ protected BufferedImage mJPEGPanelBufferedI /** Pnale to diaply the image */ public JPEGPanel() { // no op } /** Sets the bufferedimage into the class * @param bi BufferedImage */ public void setBufferedImage(BufferedImage bi) { if (bi == null) {
} mJPEGPanelBufferedImage = Dimension d = new Dimension(mJPEGPanelBufferedImage.getWidth(this), mJPEGPanelBufferedImage.getHeight(this)); setPreferredSize(d); revalidate(); repaint(); } /** Paints the component. * @param g Graphics object used for the painting */ public void paintComponent(Graphics g) { super.paintComponent(g); Dimension d = getSize(); g.setColor(getBackground()); g.fillRect(0, 0, d.width, d.height); if (mJPEGPanelBufferedImage != null) { g.drawImage(mJPEGPanelBufferedImage, 0, 0, this); } } } protected JPEGPanel mJpegP protected BufferedImage mBufferedI protected JComboBox mSourcesC protected JToolBar mToolB /** Constructor */ public JTwacker() { super(&测试&); mJpegPanel = new JPEGPanel(); JScrollPane ps = new JScrollPane(mJpegPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); getContentPane().add(ps, BorderLayout.CENTER); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); mToolBar = new JToolBar(&Twain&); mToolBar.setFloatable(false); addButtons(); getContentPane().add(mToolBar, BorderLayout.NORTH); setSize(800, 600); /* Center the frame */ Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); Rectangle frameDim = getBounds(); setLocation( (screenDim.width - frameDim.width) / 2, (screenDim.height - frameDim.height) / 2 ); setVisible(true); } protected void addButtons(){ JButton _ab = new JButton(&扫描&); _ab.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { acquireImage(); } }); mToolBar.add(_ab); mToolBar.addSeparator(); if (edu.ctgu.twain.JTwain.getInstance().isTwainAvailble()) { String[] twainSources = JTwain.getInstance().getAvailableSources(); if (twainSources != null) { mSourcesCombo = new JComboBox(twainSources); } else { mSourcesCombo = new JComboBox(); mSourcesCombo.addItem(&&NONE AVAILABLE&&); } } else { mSourcesCombo = new JComboBox(); mSourcesCombo.addItem(&&NONE AVAILABLE&&); } mToolBar.add(mSourcesCombo); } protected void acquireImage() { if (JTwain.getInstance().isTwainAvailble()){ if (mSourcesCombo.getItemCount() & 0 ){ String _source = (String)mSourcesCombo.getSelectedItem(); if (_source != null){ String _filename = JTwain.getInstance().acquire(_source); System.out.println(_filename); if (_filename != null && _filename.length() & 0) { File fChoosen = new File(_filename); // savetofile(fChoosen); showImage(fChoosen); } else { System.out.println(&哎呀,怎么出错了!&); } } // end if } // end if } // end if } protected void showImage(final File file) { if (file == null || !file.exists()) {
} setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); Thread runner = new Thread() { public void run() { try { FileInputStream in = new FileInputStream(file); JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in); mBufferedImage = decoder.decodeAsBufferedImage(); in.close(); SwingUtilities.invokeLater( new Runnable() { public void run() { reset(); } }); } catch (Exception ex) { ex.printStackTrace(); } setCursor(Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR)); } }; runner.start(); } //把扫描得到的图片保存为文件,然后上传到服务器或保存到数据库中 protected void savetofile(final File file) { try { File mfile=new File(&c:\\dd.jpg&); if (mfile.exists()) { mfile.delete(); }else { file.renameTo(mfile); } } catch (Exception e) { e.printStackTrace(); // TODO: handle exception } } protected void reset() { if (mBufferedImage != null) { mJpegPanel.setBufferedImage(mBufferedImage); } } public static void main(String argv[]) { new JTwacker(); } } ------------------------- package edu.ctgu. /* 这是调用动态链接库的类 */ public class JTwain { private static final JTwain mInstance = new JTwain(); protected final String DLL_NAME = &jtwain&; private JTwain() { initLib(); } public static JTwain getInstance(){ return mI } public native boolean isTwainAvailble(); public native String[] getAvailableSources(); public native String acquire(); public native String acquire(String sourceName); private void initLib(){ try { System.loadLibrary(DLL_NAME); }catch(Exception e) { e.printStackTrace(); } finally { // System.out.println(&Loading : & + DLL_NAME + &.dll&); } } }
采纳率:33%
为您推荐:
其他类似问题
扫描仪的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。这是静态代码扫描系列文章的第四篇,前三篇文章介绍了如何使用PMD和Findbugs自定义规则。
我们团队最近一直在研究java资源关闭的检查规则,发现市面上开源的工具针对资源关闭的检测都存在一定不足,同时也无法满足我们业务的需求。所以我们针对资源关闭进行了深度的研究,取得了一些不错的进展,但是过程的艰辛也远超了我们的预料。现在就跟大家聊聊我们的心路历程,从为什么开始。
1. 为什么要手动关闭Java资源对象?
首先解释Java的资源对象,它主要包括IO对象,数据库连接对象。比如常见的InputStream、OutputStream、Reader、Writer、Connection、Statement、ResultSet、Socket等等,先代码列举一个示例:
FileInputStream f = new FileInputStream("sample.txt");
f.close();//f对象即需要手动关闭的资源对象
上述代码中f对象即需要手动关闭的资源对象。
如果类似的资源对象没有及时的手动关闭,这个对象就会一直占据内存,当这样的对象越来越多,那内存被占用的就会越来越多,久而久之就可能造成OutOfMemory,俗称内存溢出。
这时应该有人会问,Java不是有自己的垃圾回收机制GC么?不是可以自动回收么?
这个问题问的好,我也一度非常困惑。
首先我们先了解一下GC的原理:
在Java中,当没有对象引用指向原先分配给某个对象的内存时,该内存便成为垃圾。JVM的一个系统级线程会自动释放该内存块。垃圾回收意味着程序不再需要的对象是"无用信息",这些信息将被丢弃。当一个对象不再被引用的时候,内存回收它占领的空间,以便空间被后来的新对象使用。
首先GC只能回收内存。至于各种stream之类,他们下边一般还开启了各种其他的系统资源,比如文件,比如输入输出设备(键盘/屏幕等),等等。而这些设备第一是不能自动关闭(因为谁知道你程序要用它到什么时候啊),另一个系统内数量有限(比如键盘/屏幕同一时间只有一个)。最后,文件和数据库连接之类的东西还存在读写锁定的问题。这些都导致用户必须手动处理这些资源的开启和关闭。
其次为了“避免”程序员忘了自己释放那些资源,Java提供了finalizer、PhantomReference之类的机制来让程序员向GC注册“自动回调释放资源”的功能。但GC回调它们的时机不确定,所以只应该作为最后手段来使用,主要手段还是自己关闭最好。
PS:关于GC其实有很多的知识可以深度挖掘,比如各种回收算法,finalize()方法等等,大家感兴趣的话可以自行搜索研究,我就不班门弄斧了。
2. 怎样正确的手动关闭Java资源对象?
先说一种最常见的关闭方式,在finally中进行关闭:
FileInputS
f= new FileInputStream("sample.txt");
//something that uses f and sometimes throws an exception
catch(IOException ex){
/* Handle it somehow */
f.close();
这里在finally中进行资源对象关闭属于Best Practice。因为即使对象f在使用的过程中出现异常,也能保证程序不会跳过后续的关闭操作。
特别注意,自从Java1.7开始,支持了try-with-resources写法,即将资源对象声明的过程放在try()的括号里面,这样java在资源对象使用完成之后会自动关闭。
FileOutputStream fileOutputStream = new FileOutputStream("E:\\A.txt");
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
DataOutputStream out = new DataOutputStream(bufferedOutputStream)
out.write(data1);
} catch (Exception e) {
// TODO: handle exception
另外还有一些第三方库提供了一些统一的关闭处理方法,例如
import org.apache.commons.io.IOU
public static void main(String[] args) throws Exception{
FileOutputStream fileOutputStream =
BufferedOutputStream bufferedOutputStream=
DataOutputStream out=
byte[] data1 = "这个例子测试文件写".getBytes("GB2312");
fileOutputStream = new FileOutputStream("E:\\A.txt");
bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
out = new DataOutputStream(bufferedOutputStream);
out.write(data1);
} catch (Exception e) {
// TODO: handle exception
} finally {
IOUtils.closeQuietly(out);
这个apache提供的IOUtils类库可以通过IOUtils.closeQuietly(e)的形式关闭资源对象,实际内部实现依然是调用.close()方法。内部实现代码如下:
public static void closeQuietly(final Closeable closeable) {
if (closeable != null) {
closeable.close();
} catch (final IOException ioe) {
以上就是手动关闭Java资源对象的几种推荐写法,希望对大家有所帮助。
为防止篇幅过长,这只是系列文章的第一篇,我将在下一篇继续讲述在判断资源关闭时,有哪些不为人知的特殊情况需要考虑。
敬请期待。
参考文献:
stackoverflow.
360Qtest团队公众号
关注公众号,第一时间收到我们推送的新文章~
为什么要关闭,哪些要手动关闭,怎样关闭才正确。楼主做了深入细致的钻研,支持一下
楼主干货啊!学到了!!资源关闭类做的比较深的文章比较少。希望楼主能出个系列关于资源关闭的文章。
java资源对象关闭的方法总结到位,示例鲜明。非常赞!
中提及了此贴
Java官方有安全回收IO资源的方法,即try-with-resources方法。
The try-with-resources statement ensures that each resource is closed at the end of the statement.
Any object that implements java.lang.AutoCloseable,
which includes all objects which implement java.io.Closeable, can be used as a resource.
static String readFirstLineFromFile(String path) throws IOException {
try (BufferedReader br =
new BufferedReader(new FileReader(path))) {
return br.readLine();
文中有提及“特别注意,自从Java1.7开始,支持了try-with-resources写法,即将资源对象声明的过程放在try()的括号里面,这样java在资源对象使用完成之后会自动关闭。”
看得不够仔细,抱歉啦。
哈哈,没事,欢迎随时交流。
后方可回复, 如果你还没有账号请点击这里 。
oggboy (丁老九)
第 1064 位会员 /
共收到 7 条回复I have a class called PlayGame, and in the main method I have this chunk of code:
public class PlayGame {
public static void main(String args[]) {
while (true) {
System.out.println("Where would you like your adventure to begin? (Enter a number)\n");
System.out.println("1. Play the Game\n2. Quit the Game");
Scanner userInput = new Scanner(System.in);
String userA
userAction = userInput.nextLine().trim();
if (userAction.equals("1")) {
pressPlay();
} else if (userAction.equals("2")) {
System.exit(0);
System.out.println("Sorry, your selection wasn't valid.");
} catch (Exception e) {
e.printStackTrace();
This is all fine, and when the user types 1, pressPlay() is called and it proceeds to the next method which does some stuff, mainly printing things to the screen. However, when I leave the pressPlay() method and return back to this main method, I start getting errors for reading the Input:
java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1516)
at PlayGame.main(PlayGame.java:17)
Can you clue me in into how I can get around this? Much appreciated!
EDIT - I just want it to return to the while loop in the main method and ask for 1 or 2 again, and take a valid 1 or 2. My code goes all the way through to userAction = userInput.nextLine().trim(); without waiting for anymore user input the second time round, after leaving the pressPlay() method.
EDIT - The pressPlay() method produces a grid that the player is able to move around in by typing particular commands. It has a while (true) { loop inside of it, as well as Scanner userInput = new Scanner(System.in); which takes the players input. If the player types quit, it calls a break out of the while loop and returns back to the main method, where the problem then arises.
解决方案 I've managed to fix the issue.
In both my main method and my pressPlay() method, I was creating separate scanners taking input from System.in, and this was causing problems as it would no longer take input from the main method. Instead I took the Scanner out of the main method and put it after public class PlayGame {, and used this same scanner in both of my methods, rather than separate ones.
Thank you Jayamohan and Hossam for your input (:
本文地址: &
我有一个叫 PlayGame 的类,在 main 方法中我有这个代码块: p>
public class PlayGame { public static void main(String args []){ while(true){
System.out.println(“你想在哪里开始冒险?(输入一个数字)\\\”);
System.out.println(“1。玩游戏\2,退出游戏”); 扫描仪userInput =新扫描仪(System.in);
String userA
try { userAction = userInput.nextLine()。trim();
if(userAction.equals(“1”)){ pressPlay(); } else if(userAction.equals(“2”)){ System.exit(0); } else { System.out.println(“对不起,您的选择无效”); } } catch(Exception e){ e.printStackTrace(); } } } }
当用户键入 1 时, cPress()被调用,然后继续进行下一步,主要是打印事情到屏幕但是,当我离开 pressPlay()方法并返回到此主要方法时,我开始收到错误阅读输入:
java.util.NoSuchElementException:找不到行在java.util.Scanner.nextLine(Scanner.java:1516)在PlayGame.main (PlayGame.java:17)
你能告诉我如何解决这个问题吗?非常感谢!
- 我只想让它返回到main方法的while循环,再次询问1或2,取一个有效的1或2.我的代码一直到 userAction = userInput.nextLine()。trim(); 而不用等待再次输入用户第二次离开 pressPlay()方法。
pressPlay()方法通过键入特定命令生成玩家能够移动的网格。它有一个 while(true){循环,以及 Scanner userInput = new Scanner(System.in); 这需要玩家的输入。如果播放器类型退出,它会调用while循环中的一个中断,并返回到主方法,然后出现问题。
解决方案 我已经设法解决了这个问题。
在我的主要方法和我的 pressPlay()方法,我正在创建单独的扫描仪,从 System.in 输入,这是导致问题,因为它不再从main方法输入。相反,我把Scanner退出主要方法,并将它放在 public class PlayGame {之后,并在我的两种方法中使用了相同的扫描仪,而不是单独使用。 p>
谢谢Jayamohan和Hossam的输入(:
本文地址: &
扫一扫关注官方微信

我要回帖

更多关于 java监听usb扫描枪 的文章

 

随机推荐