Я Я могу успешно запустить свое приложение без ошибок, но к остальным API, которые я напишу, невозможен правильный доступ. Я сравнил свой журнал запуска с официальными руководствами и обнаружил, что у меня нет аналогичного журнала ниже:
Код: Выделить всё
2017-11-13 17:37:50.921 INFO 6503 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2328c243: startup date [Mon Nov 13 17:37:49 CST 2017]; root of context hierarchy
2017-11-13 17:37:51.061 INFO 6503 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/greeting]}" onto public hello.Greeting hello.GreetingController.greeting(java.lang.String)
2017-11-13 17:37:51.066 INFO 6503 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-11-13 17:37:51.067 INFO 6503 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-11-13 17:37:51.126 INFO 6503 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-11-13 17:37:51.127 INFO 6503 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-11-13 17:37:51.188 INFO 6503 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
Основное приложение файл:
Код: Выделить всё
package com.teachermate;
import com.alibaba.druid.pool.DruidDataSource;
import com.teachermate.entites.TeacherMateSettings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import javax.sql.DataSource;
@SpringBootApplication
@EnableConfigurationProperties({TeacherMateSettings.class})
public class JobScheduleApplication {
@Autowired
private Environment env;
public static void main(String[] args) {
SpringApplication.run(JobScheduleApplication.class, args);
}
@Bean
public DataSource dataSource() {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl(env.getProperty("spring.datasource.url"));
dataSource.setUsername(env.getProperty("spring.datasource.username"));
dataSource.setPassword(env.getProperty("spring.datasource.password"));
dataSource.setInitialSize(2);
dataSource.setMaxActive(20);
dataSource.setMinIdle(0);
dataSource.setMaxWait(60000);
dataSource.setValidationQuery("SELECT 1");
dataSource.setTestOnBorrow(false);
dataSource.setTestWhileIdle(true);
dataSource.setPoolPreparedStatements(false);
return dataSource;
}
}
Код: Выделить всё
@RestController
@RequestMapping(path = "/test")
public class TestController {
@RequestMapping(method = RequestMethod.GET)
public JSONObject HelloWorld() {
JSONObject res = new JSONObject();
LOGGER.info("HelloWorld Test!");
res.put("data", "hello world!");
res.put("errCode", 0);
return res;
}
}
Код: Выделить всё
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.teachermate
job-scheduler
0.0.1-SNAPSHOT
jar
jobSchedule
job schedule for teachermate
org.springframework.boot
spring-boot-starter-parent
1.5.7.RELEASE
UTF-8
UTF-8
1.8
org.springframework.boot
spring-boot-starter-data-redis
org.springframework.boot
spring-boot-starter-jdbc
org.apache.tomcat
tomcat-jdbc
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
org.springframework
spring-context-support
org.springframework.boot
spring-boot-configuration-processor
true
com.alibaba
fastjson
1.2.39
mysql
mysql-connector-java
5.1.30
org.quartz-scheduler
quartz
2.2.1
com.google.guava
guava
23.2-jre
org.apache.httpcomponents
httpclient
4.3.6
com.alibaba
druid
1.0.19
org.springframework.boot
spring-boot-maven-plugin
true
Если вам нужна дополнительная информация, просто сообщите мне в комментариях.
обновление
В официальных руководствах я изменил контроллер на
Код: Выделить всё
@RestController
@RequestMapping(path = "/test")
public class GreetingController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
@RequestMapping(method = RequestMethod.GET)
public JSONObject HelloWorld() {
JSONObject res = new JSONObject();
res.put("data", "hello world!");
res.put("errCode", 0);
return res;
}
}
Подробнее здесь: https://stackoverflow.com/questions/472 ... pring-boot
Мобильная версия