springBoot
pom依赖
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.1.RELEASE</version> <relativePath/> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
修改springBoot的Tomcat端口:
在src/main/resource下新建application.properties配置文件,在文件中添加server.port=8081
即可把tomcat端口修改为8081。
新建的resource需要设置为source目录,(eclipse)Build Path/Use As Source Folder。设置完后启动即可
-------------------------------------------------------------------------------------------------------------------------------------------
如需整合mybatis,pom.xml中添加
<!-- mysql--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.21</version> </dependency> <!-- mybatis --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency>
application.properties添加
spring.datasource.url=jdbc:mysql://localhost:3306/testshop?characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=lin000
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
mybatis.mapper-locations=classpath:mapper/*.xml
resources路径下新建mapper文件夹保存xml文件,启动类添加注解@MapperScan("Dao接口的包名")或者在Dao层的类中添加@Mapper,如果不添加就会启动失败,Dao层没有放到容器中,不能使用@Autowired进行注入。会出现这种错误
Field xxx in xxxxxxxxxxx required a bean of type 'xxxxxxxxxDao' that could not be found.
Consider defining a bean of type 'xxxxxxxxxxxDao' in your configuration.
如果使用了@MapperScan后还是出现错误,就看下xml的配置文件是否有错误