小编kop*_*lov的帖子

UnsatisfiedDependencyException:使用name创建bean时出错

有几天我正在尝试创建Spring CRUD应用程序.我糊涂了.我无法解决这个错误.

org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为'clientController'的bean时出错:通过方法'setClientService'参数0表示不满意的依赖关系; 嵌套异常是org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为'clientService'的bean时出错:通过字段'clientRepository'表示的不满意的依赖关系; 嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型'com.kopylov.repository.ClientRepository'的限定bean可用:预期至少有1个bean有资格作为autowire候选者.依赖注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}

还有这个

org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为'clientService'的bean时出错:通过字段'clientRepository'表示的不满意的依赖关系; 嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型'com.kopylov.repository.ClientRepository'的限定bean可用:预期至少有1个bean有资格作为autowire候选者.依赖注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}

ClientController

@Controller
public class ClientController {
private ClientService clientService;

@Autowired
@Qualifier("clientService")
public void setClientService(ClientService clientService){
    this.clientService=clientService;
}
@RequestMapping(value = "registration/add", method = RequestMethod.POST)
public String addUser(@ModelAttribute Client client){
    this.clientService.addClient(client);
return "home";
}
}
Run Code Online (Sandbox Code Playgroud)

ClientServiceImpl

@Service("clientService")
public class ClientServiceImpl implements ClientService{

private ClientRepository clientRepository;

@Autowired
@Qualifier("clientRepository")
public void setClientRepository(ClientRepository clientRepository){
    this.clientRepository=clientRepository;
}



@Transactional
public void addClient(Client client){
    clientRepository.saveAndFlush(client);
}
}
Run Code Online (Sandbox Code Playgroud)

ClientRepository

public interface ClientRepository extends JpaRepository<Client, Integer> …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc

42
推荐指数
4
解决办法
26万
查看次数

创建名为'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping'的bean时出错

使用jdk 1.8

  1. 用SpringMVC-4.3.3
  2. SpringCore-4.3.3
  3. 的javax.servlet-API-3.0.1
  4. 弹簧数据JPA:1.10.4
  5. 休眠-的EntityManager:4.2.5.Final
  6. 休眠核心:4.2.5.Final
  7. Java的简单日志外观:1.6.1

我遇到了这样的错误

org.springframework.beans.factory.BeanCreationException:创建名为'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping'的bean时出错:init方法的调用失败; 嵌套异常是java.lang.NoSuchMethodError:org.springframework.core.annotation.AnnotatedElementUtils.hasAnnotation

我的问题:
为什么错误的鼓励和如何解决它?

web.xml中

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
     version="3.1">
<servlet>
    <servlet-name>product</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>product</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

产品servlet.xml中

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
    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="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
</bean>
<context:component-scan base-package="com.kopylov.spring.controller" />
<mvc:annotation-driven/>
Run Code Online (Sandbox Code Playgroud)

调节器

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ProductController {

@RequestMapping
public String showHome(){
    return "home";
}
Run Code Online (Sandbox Code Playgroud)

}

AppInitializer

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
Run Code Online (Sandbox Code Playgroud)

公共类AppInitializer扩展AbstractAnnotationConfigDispatcherServletInitializer { …

java spring spring-mvc spring-annotations spring-data-jpa

5
推荐指数
1
解决办法
4万
查看次数

Material UI 主题 (JetBrains) 不改变侧边栏样式

侧边栏不会更改为所需的样式,并且始终保持灰色。

如何修复这个错误?

在此输入图像描述

jetbrains-ide intellij-idea

0
推荐指数
1
解决办法
1803
查看次数