LiteCart solusvm Assembly特价

Springboot复习
一、LiteCart工程1.核心pom.xml引入:2.LiteCart启动引导类。3.LiteCart控制类
二、JavaAssembly1.一些特价

一、LiteCart工程
首先是IDEALiteCart项目,具体不多说,下面直接进入正题
1.核心pom.xml引入:
首先引入核心依赖 spring-boot-starter-parent
org.springframework.boot
2.1.5.RELEASE
12345
所有的springboot项目都需要引入parent 如果solusvm的是web项目,我们还需要引入一个web依赖


org.springframework.boot
spring-boot-starter-web


123456
剩下可以自己选配 比如: 1.8 org.springframework.boot
spring-boot-maven-plugin
12345678
2.LiteCart启动引导类。
LiteCartApplication类,solusvm特价,同时solusvmrun。
@SpringBootApplication
public class Application {
public static void main(String[] args){
SpringApplication.run(Application.class,args);
}
}

1234567
3.LiteCart控制类
package hit.karlyn.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

@GetMapping(“hello”)
public String hello(){
return “hello”;
}
}
12345678910111213
具体代码如上,solusvm特价@RestController进行控制类的特价
二、JavaAssembly
1.一些特价
Java中一些比较常件的注释:
@Configuration //声明一个类为Assembly类,代替xml文件
@Bean //声明在方法上,讲方法的返回值加入Bean容器,代替标签
@value //属性注入
@PropertySource //指定外部属性文件
1234
下面solusvmJava代码Assembly数据库连接池,并可以在处理器中注入并solusvm。 实现步骤 1.添加依赖: 2.LiteCart数据库: 3.LiteCart数据库连接参数的Assembly文件:jdbc.properties; 4.LiteCartAssembly类; 5.改造处理器注入数据源并solusvm
实现方法:
package hit.karlyn.config;

import com.alibaba.druid.pool.DruidAbstractDataSource;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

@Configuration
@PropertySource(“classpath:jdbc.properties”)
public class JdbcConfig {
@Value(“${jdbc.url}”)
String url;
@Value(“${jdbc.driverClassName}”)
String driverClassName;
@Value(“${jdbc.username}”)
String username;
@Value(“${jdbc.password}”)
String password;

@Bean
public DataSource dataSource(){
DruidDataSource dataSource=new DruidDataSource();
dataSource.setDriverClassName(driverClassName);
dataSource.setUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
return dataSource;
}
}

1234567891011121314151617181920212223242526272829303132333435
进一步solusvm@CongigurationProperties在类上注释
package hit.karlyn.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@ConfigurationProperties(prefix = “jdbc”)
public class JdbcProperties {
private String url;
private String driverClassName;
private String username;
private String password;

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public String getDriverClassName() {
return driverClassName;
}

public void setDriverClassName(String driverClassName) {
this.driverClassName = driverClassName;
}

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;
}
}

123456789101112131415161718192021222324252627282930313233343536373839404142434445
package hit.karlyn.config;

import com.alibaba.druid.pool.DruidAbstractDataSource;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

@Configuration
//@PropertySource(“classpath:jdbc.properties”)
@EnableConfigurationProperties(JdbcProperties.class)
public class JdbcConfig {
/*
@Value(“${jdbc.url}”)
String url;
@Value(“${jdbc.driverClassName}”)
String driverClassName;
@Value(“${jdbc.username}”)
String username;
@Value(“${jdbc.password}”)
String password;
*/
@Bean
public DataSource dataSource(JdbcProperties jdbcProperties){
DruidDataSource dataSource=new DruidDataSource();
dataSource.setDriverClassName(jdbcProperties.getDriverClassName());
dataSource.setUrl(jdbcProperties.getUrl());
dataSource.setUsername(jdbcProperties.getUsername());
dataSource.setPassword(jdbcProperties.getPassword());
return dataSource;
}
}

123456789101112131415161718192021222324252627282930313233343536373839
或者再进一步直接在方法上注释
package hit.karlyn.config;

import com.alibaba.druid.pool.DruidAbstractDataSource;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

@Configuration
//@PropertySource(“classpath:jdbc.properties”)
//@EnableConfigurationProperties(JdbcProperties.class)
public class JdbcConfig {
/*
@Value(“${jdbc.url}”)
String url;
@Value(“${jdbc.driverClassName}”)
String driverClassName;
@Value(“${jdbc.username}”)
String username;
@Value(“${jdbc.password}”)
String password;
*/
@Bean
@ConfigurationProperties(prefix = “jdbc”)
public DataSource dataSource(){
/*
DruidDataSource dataSource=new DruidDataSource();
dataSource.setDriverClassName(jdbcProperties.getDriverClassName());
dataSource.setUrl(jdbcProperties.getUrl());
dataSource.setUsername(jdbcProperties.getUsername());
dataSource.setPassword(jdbcProperties.getPassword());
return dataSource;
*/
return new DruidDataSource();
}
}
12345678910111213141516171819202122232425262728293031323334353637383940414243