我读到了关于Spring如何鼓励你在代码中使用接口的地方.我没有看到它.spring xml配置中没有接口的概念.Spring的哪一部分实际上鼓励您使用接口(除了文档)?
我正在尝试从存储在jar文件中的动画gif创建一个ImageIcon.
ImageIcon imageIcon = new ImageIcon(ImageIO.read(MyClass.class.getClassLoader().getResourceAsStream("animated.gif")));
Run Code Online (Sandbox Code Playgroud)
图像加载,但只加载动画gif的第一帧.动画无法播放.
如果我从文件系统上的文件加载动画gif,一切都按预期工作.动画播放所有帧.这样可行:
ImageIcon imageIcon = new ImageIcon("/path/on/filesystem/animated.gif");
Run Code Online (Sandbox Code Playgroud)
如何从jar文件中将动画gif加载到ImageIcon中?
编辑:这是一个完整的测试用例,为什么不显示动画?
import javax.imageio.ImageIO;
import javax.swing.*;
public class AnimationTest extends JFrame {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
AnimationTest test = new AnimationTest();
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
test.setVisible(true);
}
});
}
public AnimationTest() {
super();
try {
JLabel label = new JLabel();
ImageIcon imageIcon = new ImageIcon(ImageIO.read(AnimationTest.class.getClassLoader().getResourceAsStream("animated.gif")));
label.setIcon(imageIcon);
imageIcon.setImageObserver(label);
add(label);
pack();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud) 现在我有字段"String firstName"它转换为"first_name",我希望"firstname"作为Hibernate的默认值.它可以吗?
我是Hibernate的新手,并尝试运行一个java/spring示例,该示例从MS SqlServer中的表中检索数据.每次我尝试运行程序时,数据源加载正常.但是当spring尝试加载会话facotry时会出现以下错误:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory'
defined in class path resource [ml/spring/src/applicationContext.xml]:
Instantiation of bean failed; nested exception is
java.lang.NoClassDefFoundError: javax/transaction/TransactionManager
Caused by: java.lang.NoClassDefFoundError: javax/transaction/TransactionManager
Run Code Online (Sandbox Code Playgroud)
下面是我正在使用的应用程序上下文文件:
<!-- Data source bean -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName">
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value></property>
<property name="url">
<value>jdbc:microsoft:sqlserver://machine:port</value></property>
<property name="username"><value>user</value></property>
<property name="password"><value>password</value></property>
</bean>
<!-- Session Factory Bean -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref local="dataSource"/></property>
<property name="mappingResources">
<list>
<value>authors.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=net.sf.hibernate.dialect.SQLServerDialect
</value>
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"> …Run Code Online (Sandbox Code Playgroud) [1]在JDBC中,我们为什么要首先使用Class.forName("some driver name")加载驱动程序.为什么SUN没有在getConnection()方法本身中处理加载驱动程序.如果我将驱动程序名称作为参数传递给getConnection()方法.
[2]我想了解JBDC的内部结构.对它的任何指示都表示赞赏.