我正在开始我的春季应用,但是当我尝试在浏览器中访问我的网址时,这样:localhost:8080/register
我得到了这个NullPointerException
:
:: Spring Boot :: (v1.4.0.RELEASE)
2016-08-10 17:10:39.646 INFO 8300 --- [ main] com.inveitix.register.Application : Starting Application on Tito-PC with PID 8300 (started by Tito in D:\workspace-sts-3.8.1.RELEASE\Organization Register)
2016-08-10 17:10:39.649 INFO 8300 --- [ main] com.inveitix.register.Application : No active profile set, falling back to default profiles: default
2016-08-10 17:10:40.035 INFO 8300 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@1283bb96: startup date [Wed Aug 10 17:10:40 EEST 2016]; root of context hierarchy
2016-08-10 17:10:41.110 INFO 8300 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'dataSource' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Dbcp; factoryMethodName=dataSource; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Dbcp.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Tomcat; factoryMethodName=dataSource; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]]
2016-08-10 17:10:41.586 INFO 8300 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-08-10 17:10:41.766 INFO 8300 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$f7bab930] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-08-10 17:10:42.541 INFO 8300 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-08-10 17:10:42.558 INFO 8300 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2016-08-10 17:10:42.559 INFO 8300 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.4
2016-08-10 17:10:42.761 INFO 8300 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-08-10 17:10:42.762 INFO 8300 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2732 ms
2016-08-10 17:10:42.993 INFO 8300 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2016-08-10 17:10:42.997 INFO 8300 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-08-10 17:10:42.997 INFO 8300 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-08-10 17:10:42.997 INFO 8300 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-08-10 17:10:42.997 INFO 8300 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2016-08-10 17:10:43.362 INFO 8300 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2016-08-10 17:10:43.387 INFO 8300 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2016-08-10 17:10:43.474 INFO 8300 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.2.2.Final}
2016-08-10 17:10:43.476 INFO 8300 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2016-08-10 17:10:43.478 INFO 8300 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2016-08-10 17:10:43.531 INFO 8300 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2016-08-10 17:10:44.086 INFO 8300 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2016-08-10 17:10:44.705 INFO 8300 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2016-08-10 17:10:45.328 INFO 8300 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@1283bb96: startup date [Wed Aug 10 17:10:40 EEST 2016]; root of context hierarchy
2016-08-10 17:10:45.424 INFO 8300 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/create]}" onto public java.lang.String com.inveitix.register.contollers.RegistrationController.create(com.inveitix.register.models.Organization)
2016-08-10 17:10:45.425 INFO 8300 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/register],methods=[POST]}" onto public java.lang.String com.inveitix.register.contollers.RegistrationController.registerSubmit(com.inveitix.register.models.Organization,org.springframework.ui.Model)
2016-08-10 17:10:45.425 INFO 8300 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/register],methods=[GET]}" onto public java.lang.String com.inveitix.register.contollers.RegistrationController.registerForm(org.springframework.ui.Model)
2016-08-10 17:10:45.428 INFO 8300 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-08-10 17:10:45.429 INFO 8300 --- [ 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)
2016-08-10 17:10:45.465 INFO 8300 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-08-10 17:10:45.466 INFO 8300 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-08-10 17:10:45.529 INFO 8300 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-08-10 17:10:46.288 INFO 8300 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-08-10 17:10:46.357 INFO 8300 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-08-10 17:10:46.362 INFO 8300 --- [ main] com.inveitix.register.Application : Started Application in 7.161 seconds (JVM running for 7.796)
2016-08-10 17:10:51.254 ERROR 8300 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost] : Exception Processing /register
java.lang.NullPointerException: null
at org.apache.catalina.authenticator.AuthenticatorBase.getJaspicProvider(AuthenticatorBase.java:1140) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:431) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.4.jar:8.5.4]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_71]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_71]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.4.jar:8.5.4]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_71]
你能帮帮我吗?
这是我的aplication.properties
文件:
spring.datasource.url = jdbc:mysql://localhost:3306/organizationsbd
spring.datasource.username = admin
spring.datasource.password = admin
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.hibernate.naming.strategy = org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
这是我的控制者:
@Controller
public class RegistrationController {
@RequestMapping(value = "/register", method = RequestMethod.GET)
public String registerForm(Model model) {
model.addAttribute("organization", new Organization());
return "register";
}
@RequestMapping(value = "/register", method = RequestMethod.POST)
public String registerSubmit(@ModelAttribute Organization organization, Model model) {
model.addAttribute("organization", organization);
create(organization);
return "result";
}
@RequestMapping("/create")
@ResponseBody
public String create(Organization organization) {
String ogranizationId = "";
try {
organizationDao.save(organization);
ogranizationId = String.valueOf(organization.getId());
} catch (Exception ex) {
return "Error creating the user: " + ex.toString();
}
return "User succesfully created with id = " + ogranizationId;
}
@Autowired
private OrganizationDao organizationDao;
}