作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 spring 项目,我可以在导出 jar 文件之前从 spring 上下文中获取 spring bean。我导出 jar 文件并在 cmd 上运行该 jar 文件。我得到了NoSuchBeanDefinitationException
。该项目找不到 spring bean。我用过<context:component-scan>
在 spring 配置文件中。我想知道问题是什么?
编辑
在 bean 中
package com.example.userprofile;
@Service("UserProfileManager")
@Transactional
public class UserProfileManagerImpl implements UserProfileManager{
@Autowired
private UserProfileDao userProfileDao;
在spring配置文件中
<context:component-scan
base-package="com.example" />
<tx:annotation-driven transaction-manager="transactionManager" />
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="com.mysql.jdbc.Driver" p:url="jdbc:mysql://localhost:3309/test"
p:username="root" p:password="root" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>hibernate.cfg.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
当我使用 JBoss IDE 测试该项目时,它运行得很好。但是当我将项目导出到jar文件并在cmd上运行时。我收到以下错误。
here是我的项目 zip 文件。抱歉更新晚了。
最佳答案
虽然问题陈述太宽泛,无法提供具体答案,但您可以执行以下操作:
如果没有任何内容跳出,请粘贴整个堆栈跟踪,而不仅仅是代码片段以及 jar 的结构,以便我们也能看到与您相同的大图。
关于java - 导出 jar 文件后 Spring NoSuchBeanDefinitationException 抛出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24948050/
我有 spring 项目,我可以在导出 jar 文件之前从 spring 上下文中获取 spring bean。我导出 jar 文件并在 cmd 上运行该 jar 文件。我得到了NoSuchBeanD
我是一名优秀的程序员,十分优秀!