新建一个maven spring boot项目中遇到的问题
2017-04-25 11:27
1081 查看
1.问题:xxx.jar中没有主清单属性
命令:make debug
结果:
解决:查找资料发现MAVEN插件打包生成的jar包中的META-INF/MANIFEST.MF文件,没有设置主函数信息。配置pom.xml即可;
(如果直接配置则会报错→问题2)
现在配置为:
2.问题:<plugin>不能识别
命令:make install
结果:
命令:make debug
结果:
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中没有主清单属性
解决:查找资料发现MAVEN插件打包生成的jar包中的META-INF/MANIFEST.MF文件,没有设置主函数信息。配置pom.xml即可;
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin>
(如果直接配置则会报错→问题2)
现在配置为:
2.问题:<plugin>不能识别
命令:make install
结果:
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[/code]
原因:未加上<build>
3.问题:target/xxx.jar找不到
命令:make debug
结果:
原因:检查target目录下的jar包名,发现与Makefile中写的不符合。将debug和run里面的名字改成对的即可。
4.问题:Consider defining a bean of type 'service.IUserInfoService' in your configuration.
命令:make debug
结果:
解决方案:加入config,并在UserController.java中加入注解@SpringBootApplication(scanBasePackages = {"service","dao","config”})
解决过程:
在工程中加入config文件,配置如下: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<>(); 9b9a 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; } }
一开始只加入了service,先扫service包,发现error变成了'dao.UserInfoMapper'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.
可以看出实际上是因为Mapper没有被扫到,所以增加dao和config的扫描。
改成@SpringBootApplication(scanBasePackages = {"service","dao","config”})把包都扫到之后,编译通过。
相关文章推荐
- springmvc+mybatis+maven项目集成的时候遇到一个问题,项目搭起来以后,http请求怎么都进不到controller中,页面直接返回404错误,控制台没有报任何错误,请大神帮我看看
- IDEA上面搭建一个SpringBoot的web-mvc项目遇到的问题
- spring Boot项目遇到的一个小问题学习到repeatable annotations
- 如何在eclipse以外用浏览器新建一个Maven的SpringBoot项目
- springmvc+mybatis+maven项目集成的时候遇到一个问题,项目搭起来以后,http请求怎么都进不到controller中,页面直接返回404错误,控制台没有报任何错误,请大神帮我看看
- 使用maven构建一个Spring Boot项目
- springboot入门一,使用myEclipse新建一个springboot项目
- idea遇到的问题-无法新建maven 项目
- 遇到问题---maven---启动项目出现出现 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoa
- 【demo】新建一个springboot项目最简单的方法
- intellij idea maven springMVC和SpringBoot遇到的两个小问题
- [置顶] 使用maven创建一个spring-boot项目-集成springmvc
- spring tool suite 新建maven项目报错问题
- <springBoot>(三)(入门篇)新建一个springBoot项目(两种启动的方式)
- Maven使用中新建项目遇到的问题
- 在Windows新建一个cocos-2d的项目遇到的问题
- spring-boot创建项目遇到配置问题
- spring-boot中关于Maven依赖管理的一个问题
- 遇到的问题----新建maven项目ArtifactTransferException 和Execution default-testResources of goal或者导入maven报错
- 用Spring Boot 构建项目中遇到问题及解决方法