Consider defining a bean of type 'package' in your configuration [Spring-Boot]
https://stackoverflow.com/questions/40384056/consider-defining-a-bean-of-type-package-in-your-configuration-spring-boot
http://blog.csdn.net/u012049760/article/details/70691925
Your Applicant class is not scanned it seems. By default all packages starting with the root as the class where you have put @SpringBootApplication
will be scanned.
suppose your main
class "WebServiceApplication" is in "com.service.something
", then all components that fall under "com.service.something
" is scanned, and "com.service.applicant
" will not be scanned.
You can either restructure your packages such that "WebServiceApplication" falls under a root package and all other components becomes part of that root package. Or you can include @SpringBootApplication(scanBasePackages={"com.service.something","com.service.application"})
etc such that "ALL" components are scanned and initialized in the spring container.
Update based on comment
If you have multiple modules that are being managed by maven/gradle, all spring needs is the package to scan. You tell spring to scan "com.module1" and you have another module which has its root package name as "com.module2", those components wont be scanned. You can even tell spring to scan "com" which will then scan all components in "com.module1.
" and "com.module2.
"
I am not sure if it is because I have my project broke down in modules but this is how I solved my issue of not be able to find my repositories.
|
- java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5033 -Dgrpc.port=6033 -Dserver.port=8033 -jar target/demo-1.0-SNAPSHOT.jar
- Listening for transport dt_socket at address: 5033
- target/demo-1.0-SNAPSHOT.jar中没有主清单属性
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- mvn clean install -DskipTests
- [INFO] Scanning for projects...
- [ERROR] [ERROR] Some problems were encountered while processing the POMs:
- [ERROR] Malformed POM /Users/********/Documents/workspace/pom.xml: Unrecognised tag: 'plugin' (position: START_TAG seen ...</repositories>\n\n <plugin>... @38:13) @ /Users/********/Documents/workspace/pom.xml, line 38, column 13
- @
- [ERROR] The build could not read 1 project -> [Help 1]
- [ERROR]
- [ERROR] The project com.mobike:demo:1.0-SNAPSHOT (/Users/********/Documents/workspace/pom.xml) has 1 error
- [ERROR] Malformed POM /Users/********/Documents/workspace/pom.xml: Unrecognised tag: 'plugin' (position: START_TAG seen ...</repositories>\n\n <plugin>... @38:13) @ /Users/********/Documents/workspace/pom.xml, line 38, column 13 -> [Help 2]
- [ERROR]
- [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
- [ERROR] Re-run Maven using the -X switch to enable full debug logging.
- [ERROR]
- [ERROR] For more information about the errors and possible solutions, please read the following articles:
- [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
- [ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/ModelParseException
- package config;
- import com.alibaba.druid.pool.DruidDataSource;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.ibatis.session.SqlSessionFactory;
- import org.mybatis.spring.SqlSessionFactoryBean;
- import org.mybatis.spring.annotation.MapperScan;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.core.io.Resource;
- import org.springframework.core.io.support.ResourcePatternResolver;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.springframework.jdbc.datasource.DataSourceTransactionManager;
- import org.springframework.stereotype.Repository;
- import javax.annotation.PostConstruct;
- import javax.annotation.PreDestroy;import javax.sql.DataSource;
- import java.io.IOException;import java.sql.SQLException;import java.util.ArrayList;
- import java.util.Arrays;import java.util.List;
- @Slf4j
- @Configuration
- @MapperScan(basePackages = {
- "dao",}, annotationClass = Repository.class, sqlSessionFactoryRef = SysUserAuthDaoConfig.SQL_SESSION_FACTORY_NAME)
- public class SysUserAuthDaoConfig {
- public static final String SQL_SESSION_FACTORY_NAME = "opsSqlSessionFactory";
- @Value("${ops.database.username}")
- private String username;
- @Value("${ops.database.password}")
- private String password;
- @Value("${ops.database.url}")
- private String url;
- @Value("classpath:mybatis.userinfo/*.xml")
- private String mapperLocation;
- private DruidDataSource dataSource;
- private DataSourceTransactionManager transactionManager;
- private SqlSessionFactory sqlSessionFactory;
- @Autowired private ResourcePatternResolver resourceResolver;
- public String getUsername() {
- return username; }
- public void setUsername(String username) {
- this.username = username; }
- public String getPassword() {
- return password; }
- public void setPassword(String password) {
- this.password = password; }
- public String getUrl() {
- return url; }
- public void setUrl(String url) {
- this.url = url; }
- public String getMapperLocation() {
- return mapperLocation; }
- public void setMapperLocation(String mapperLocation) {
- this.mapperLocation = mapperLocation; }
- public String[] getMapperLocations() {
- String[] mapperLocations = new String[1]; mapperLocations[0] = getMapperLocation(); return mapperLocations; }
- @PostConstruct public void init() {
- try {
- log.info("Init datasource: url: {}", url); dataSource = new DruidDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl(url); dataSource.setUsername(username); dataSource.setPassword(password); dataSource.setTestWhileIdle(true); dataSource.setTestOnReturn(false); dataSource.init();
- transactionManager = new DataSourceTransactionManager(); transactionManager.setDataSource(dataSource); log.info("Init done"); } catch (Throwable t) {
- log.error("Init error", t); }
- }
- @PreDestroy public void destroy() {
- try {
- log.info("Close {}", url); dataSource.close(); log.info("Close {} done", url); } catch (Throwable t) {
- log.error("Destroy error", t); }
- }
- @Bean(name = SQL_SESSION_FACTORY_NAME)
- public SqlSessionFactory sqlSessionFactoryBean() throws Exception {
- if (sqlSessionFactory == null) {
- SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); org.apache.ibatis.session.Configuration
- config = new org.apache.ibatis.session.Configuration(); config.setMapUnderscoreToCamelCase(true); sqlSessionFactoryBean.setConfiguration(config); sqlSessionFactoryBean.setDataSource(dataSource); List<Resource> resources = new ArrayList<>(); if (this.getMapperLocations() != null) {
- for (String mapperLocation : this.getMapperLocations()) {
- try {
- Resource[] mappers = resourceResolver.getResources(mapperLocation); resources.addAll(Arrays.asList(mappers)); } catch (IOException e) {
- log.error("IOException", e); return null; }
- }
- }
- Resource[] arr = resources.toArray(new Resource[resources.size()]); sqlSessionFactoryBean.setMapperLocations(arr); sqlSessionFactory = sqlSessionFactoryBean.getObject(); }
- return sqlSessionFactory; }
- @Bean("sysUserAuthJdbcTemplate")
- public JdbcTemplate jdbcTemplate() {
- return new JdbcTemplate(this.dataSource); }
- @Bean("sysUserAuthDataSource")
- public DataSource getDatabase() throws SQLException {
- return dataSource; }
- @Bean("sysUserAuthTransactionManager")
- public DataSourceTransactionManager transactionManager() {
- return transactionManager; }
- }
- Description:
- Field userInfoMapper in service.UserInfoServiceimpl required a bean of type 'dao.UserInfoMapper' that could not be found.
- Action:
- Consider defining a bean of type 'dao.UserInfoMapper' in your configuration.
Consider defining a bean of type 'package' in your configuration [Spring-Boot]的更多相关文章
- springboot 工程启动报错之Consider defining a bean of type ‘XXX’ in your configuration.
一.前言: 使用springboot自动注入的方式搭建好了工程,结果启动的时候报错了!!!,错误如下图: Description: Field userEntityMapper in com.xxx. ...
- 关于spring boot自动注入出现Consider defining a bean of type 'xxx' in your configuration问题解决方案
搭建完spring boot的demo后自然要实现自动注入来体现spring ioc的便利了,但是我在实施过程中出现了这么一个问题,见下面,这里找到解决办法记录下来,供遇到同样的问题的同僚参考 Des ...
- Consider defining a bean of type `xxx` in your configuration问题解决
在使用SpringBoot装配mybatis时出现了异常 *************************** APPLICATION FAILED TO START *************** ...
- IntelliJ IDEA 2017版 spring-boot 报错Consider defining a bean of type 'xxx' in your configuration问题解决方案
问题分析: 通过问题的英文可知,这个错误是service的bean注入失败,那么为什么会产生这个问题呢? 主要是框架的Application产生的,所以我们建立项目的时候,要保证项目中的类跟Appli ...
- springboot Consider defining a bean of type 'xxx' in your configuration
这个错误是service的bean注入失败,主要是Application位置不对,要保证项目中的类在Application启动服务器类的下一级目录,如图:
- spring boot注入error,Consider defining a bean of type 'xxx' in your configuration问题解决方案
经常出现这问题一定是非spring生态圈的@标签 没被spring引入,如mybatis等 因为在默认情况下只能扫描与控制器在同一个包下以及其子包下的@Component注解,以及能将指定注解的类自动 ...
- Spring Boot:Consider defining a bean of type '*.*.*' in your configuration解决方案
果然不看教程直接使用在遇到问题会懵逼,连解决问题都得搜半天还不一定能帮你解决了... ***************************APPLICATION FAILED TO START*** ...
- Consider defining a bean of type 'com.lvjing.dao.DeviceStatusMapper' in your configuration.
"C:\Program Files\Java\jdk1.8.0_181\bin\java.exe" "-javaagent:C:\Program Files\JetBra ...
- Consider defining a bean of type 'org.springframework.data.redis.connection.RedisConnectionFactory' in your configuration
Description: Parameter 0 of method redisTemplate in com.liaojie.cloud.auth.server.config.redis.Redis ...
随机推荐
- es6 vs commonjs
'use strict' export function showMe() { alert("es6"); }; class logging { constructor() { a ...
- vue之mapMutaions的使用 && vuex中 action 用法示例 && api.js的使用
vue之mapMutations的使用 我们通过Mutation来改变store中的state,方法往往是在子组件中使用 this.$store.commit(); 来实现,但是这样的缺点是不容易查看 ...
- cloudermanager安装过程中出现W:GPG error错误 http://ppa.launchpad.net.trusty Release **** 4DF9B28CA252A784(图文详解)
不多说,直接上干货! 问题详情 解决办法 sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4DF9B28CA252A784 ...
- 【ExtJS】关于constructor、initComponent、beforeRender
ExtJS提供的组件非常丰富,不过当原生的组件无法满足要求时,就需要扩展原生自定义组件了. initComponent 和 constructor 就是Extjs 提供用来实现继承和扩展的方式. 在E ...
- 【计算机网络】HTTP请求和响应格式
HTTP请求格式:<request-line><headers><blank line>[<request-body>]说明:第一行必须是一个请求行(r ...
- ubuntu中mysql5.7表名区分大小写解决方案
在/etc/mysql/mysql.conf.d/mysqld.cnf 添加lower_case_table_names=1
- 白话SpringCloud | 第五章:服务容错保护(Hystrix)
前言 前一章节,我们知道了如何利用RestTemplate+Ribbon和Feign的方式进行服务的调用.在微服务架构中,一个服务可能会调用很多的其他微服务应用,虽然做了多集群部署,但可能还会存在诸如 ...
- bzoj 5308: [Zjoi2018]胖
Description Cedyks是九条可怜的好朋友(可能这场比赛公开以后就不是了),也是这题的主人公. Cedyks是一个富有的男孩子.他住在著名的ThePLace(宫殿)中. Cedyks是一个 ...
- 错误:38-Corel VideoStudio文件已损坏或被修改。请重新安装原始来源解决方法。
打开 Corel VideoStudio Pro X5(绘声绘影)弹出一下警告. 错误:38-Corel VideoStudio文件已损坏或被修改.请重新安装原始来源解决方法. [第一方法]:控制面板 ...
- HDU 4268 multiset
http://acm.hust.edu.cn/vjudge/contest/123100#problem/B #include <iostream> #include <string ...