当前位置: 首页 > 知识库问答 >
问题:

不能奥托瓦尔。找不到...类型的bean

曹原
2023-03-14

你能帮我解决为什么我不能上课吗??UserDAOImpl类:

@Repository
public class UserDaoImpl implements UserDao {

    @Autowired
    private SessionFactory sessionFactory;

    @Override
    public void addUser(User user) {
        sessionFactory.getCurrentSession().save(user);
    }

    @Override
    public List<User> getUsers() {
        return sessionFactory.getCurrentSession().createSQLQuery("SELECT * FROM user").list();
    }

}

我想让这个班变成另一个班:

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao; //here is the error

    @Override
    public void addUser(User user) {

    }

    @Override
    public List<User> getUsers() {
        return null;
    }

}
@Controller
public class UserController {

    @Autowired
    UserService userService;

    String message = "This should be a list of users";

    @RequestMapping("/user")
    public ModelAndView showMessage() {
        ModelAndView modelAndView = new ModelAndView("user");
        modelAndView.addObject("message", message);
        return modelAndView;
    }

}
<?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-3.0.xsd">

    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                <prop key="hibernate.connection.driver_class">org.postgresql.Driver</prop>
                <prop key="hibernate.connection.url">jdbc:postgresql://localhost:8080/****</prop>
                <prop key="hibernate.connection.username">****</prop>
                <prop key="hibernate.connection.password">****</prop>
                <prop key="hibernate.current_session_context_class">thread</prop>
                <prop key="show_sql">true</prop>
            </props>
        </property>
        <property name="annotatedClasses">
            <list>
                <value>model.User</value>
            </list>
        </property>
    </bean>

 </beans>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">

    <display-name>Archetype Created Web Application</display-name>

    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

</web-app>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       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-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package="controller" />

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/" />
        <property name="suffix" value=".jsp" />
    </bean>

</beans>

共有1个答案

田远
2023-03-14

不要在打印bean之前打印@autowired。否则,…类型的No bean found将出现@autowired private ProjectRepository ProjectRepository;

 类似资料:
  • IDEA编译器报告错误,但项目可以正常运行。原因何在?IDEA编译器报告错误,但项目可以正常运行。原因何在?

  • 谷歌宣布,自2019年8月1日起,所有新应用程序和应用程序更新都必须提供64位版本和32位版本。我有一个Ionic 3(Cordova)应用程序,我不确定这会有什么影响。具体来说,爱奥尼亚/科尔多瓦应用程序需要做什么才能满足这一要求? 从2019年8月1日开始: 发布到Google Play时,除了32位版本外,所有包含本机代码的新应用和应用更新都必须提供64位版本。

  • 我在Spring网站上跟踪这个SpringBoot演示,学习如何创建一个接受上传的文件。我收到一条错误消息: 我试图通过向FileUploadController添加注释来修复它。 我已尝试将以下依赖项添加到build.gradle 注意:我不想将数据库连接到此演示项目。这个演示确认它不是在这个演示中尝试连接数据库,而是在生产环境中尝试连接数据库。 我尝试在Storage Service接口上方添

  • 当开始使用模型时,我得到了以下错误 未找到类帖子。 我所做的一切: -使用命令 -尝试使用

  • 我正在使用和。它在这里 我有一个像这样的域名。而且,似乎不推荐使用注释,所以我使用了。 类如下所示 使用该类的如下所示 但当我启动应用程序时,我得到了错误 问题出在哪里?