Προς το περιεχόμενο

error 500 Spring MVC - AngularJS


Προτεινόμενες αναρτήσεις

Δημοσ.

Καλησπέρα σας παιδιά...δεν πέρασε πολύς καιρός απο το τελευταίο post και ξαναχτυπάω :P

Εχω μια σελίδα εγγραφής όπου παίρνω τα στοιχεία που εισάγει ο χρήστης και τα αποθηκεύω σε mysql χρησιμοποιώντας ngResource την default εντολή $save ωστόσο μου εμφανίζεται error 500

Παρακάτω επισυνάπτω τον Spring Controller, Angular Controller,Angular ngResource Service και την σελίδα που κάνω εγγραφη...

 

Το Service μου στην Angular

app.factory('Person', ['$resource', function ($resource) {
    return $resource('http://localhost:8080/FindTheLoc/signUp/person/:personId', {personId: '@pid'},
	{
		updatePerson: {method: 'PUT'}
	}
    );
}]);

o Controller μου στην Angular

app.controller('PersonController', ['$scope', 'Person', function($scope, Person) {
   
	var ob = this;
    ob.persons=[];
    ob.person = new Person(); 
    ob.fetchAllPersons = function(){
        ob.persons = Person.query();
    };
    ob.fetchAllPersons();
    ob.addPerson = function(){
	
	  ob.person.$save(function(person){
	     console.log(person); 
	     ob.flag= 'created';	
	     ob.reset();	
	     ob.fetchAllPersons();
	  }
	  
          )};
        
  
    
    ob.reset = function(){
    	ob.person = new Person();
        $scope.personForm.$setPristine();
    };	
       
    
    
    }]);

signUp.jsp σελίδα 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<html>

<head>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/resources/myStyleFile/myStyle.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta charset="UTF-8">
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
    <script type="text/javascript" src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-resource.min.js"></script>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAZq3N4iOcyQ0Bi7UC2FukTPMWbULtBuFo&libraries=places"></script>
    <title>FindTheLoc</title>
</head>

<body ng-app='myApp'>
     <div class="backgroundDiv"> 
        </div>
    <video poster="${pageContext.request.contextPath}/resources/myStyleFile/images/screen.png" id="bgvid" playsinline autoplay muted loop>
        <source src="${pageContext.request.contextPath}/resources/myStyleFile/images/screenVideo.mp4" type="video/mp4">
    </video>
    <div>
        <img class="menu-img" tabindex="1" src="resources/myStyleFile/images/menu.png" alt="Menu" title="Menu">
        <ul class="navigation">
            <li><a href="${pageContext.request.contextPath}/">Αρχική</a></li>
            <li><a href="${pageContext.request.contextPath}/signIn">Σύνδεση</a></li>
            <li><a href="${pageContext.request.contextPath}/signUp">Εγγραφή</a></li>
        </ul>
    </div>
  
  <!-- Εδώ γίνεται το save action -->

    <div class="div-signUp" ng-controller="PersonController as personCtrl">
        <h2>Εγγραφή</h2>

        <form id="signUp-Fomm"  name="personForm" method="POST">
            <p>Όνομα Χρήστη:</p><input type="text" name="name" ng-model="personCtrl.person.name" required /> <br>
            <p>Κωδικός:</p><input type="password" name="password" ng-model="personCtrl.person.pass" required /><br>
            <p>Τηλέφωνο:</p><input type="tel" name="telephone" ng-model="personCtrl.person.telephone" required /><br>
            <p>Εmail:</p><input type="email" name="email" ng-model="personCtrl.person.email" required /><br>
            <p>Χώρα:</p><input type="text" name="country" ng-model="personCtrl.person.country" required /><br>
            <p>Διεύθυνση:</p><input type="text" name="address" ng-model="personCtrl.person.address" required /><br>
            <button type="submit" ng-click="personCtrl.addPerson()" value="Add Person">Υποβολή</button>
          
        </form>
        
    </div>
    <footer>
        <p>FindTheLoc Copyrights 2017</p>
    </footer>
    <script type="text/javascript" src="${pageContext.request.contextPath}/resources/javascriptFiles/app.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/resources/javascriptFiles/Services/user.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/resources/javascriptFiles/Controllers/userController.js"></script>
</body>

</html>

Spring Controller

package gr.findtheloc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.util.UriComponentsBuilder;

import gr.findtheloc.model.User;
import gr.findtheloc.service.UserService;



@Controller
public class UserController {
	
	@Autowired
	private UserService personService;
	
	@RequestMapping(value = "/signUp", method = RequestMethod.GET)
	public String getSignUp(Model model) {
		
		return "signUp";
	}
	
	@RequestMapping(value = "/signIn", method = RequestMethod.GET)
	public String getIndex(Model model) {
		
		return "signIn";
	}

	
	
	 @RequestMapping(value = "/signUp/person", method = RequestMethod.POST)
	    public ResponseEntity<Void> createUser(@RequestBody User user,    UriComponentsBuilder ucBuilder) {
	        System.out.println("Creating User " + user.getUsername());
	  
	  
	        personService.create(user);
	  
	        HttpHeaders headers = new HttpHeaders();
	        headers.setLocation(ucBuilder.path("/user/{id}").buildAndExpand(user.getId()).toUri());
	        return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
	    }
	
	
}

SEVERE: Servlet.service() for servlet [view] in context with path [/FindTheLoc] threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: org.hibernate.exception.ConstraintViolationException: could not execute statement; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement] with root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'password' cannot be null
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

και παραπάνω είναι το σφάλμα που μου εμφανίζει η java

 

η mysql μου

CREATE DATABASE  IF NOT EXISTS `findtheloc` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
USE `findtheloc`;

CREATE TABLE  `user` (
  `id` bigint(10) unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(45),
  `password` varchar(45) NOT NULL,
  `telephone` varchar(45) NOT NULL,
  `email` varchar(45) NOT NULL,
  `country` varchar(45) NOT NULL,
  `address` varchar(45) NOT NULL
  PRIMARY KEY (`id`),
  UNIQUE KEY `email_UNIQUE` (`email`),
  UNIQUE KEY `password_UNIQUE` (`password`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 


CREATE TABLE IF NOT EXISTS `favourite` (
  `id` bigint(10) unsigned NOT NULL AUTO_INCREMENT,
  `location` varchar(150),
  `user_id` bigint(10) unsigned NOT NULL,
  `created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 

το model μου

package gr.findtheloc.model;

import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity

@Table(name = "user")

public class User {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id")

	private Long id;

	private String username;

	private String password;

	private String telephone;

	private String email;

	private String country;

	private String address;

	public User() {
		super();
	}

	public User(Long id,String username, String password, String telephone, String email, String country,
			String address) {
		this.id = id;
		this.username = username;
		this.password = password;
		this.telephone = telephone;
		this.email = email;
		this.country = country;
		this.address = address;
	}

	public Long getId() {
		return id;
	}
	
	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 getTelephone() {
		return telephone;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	

}

τι κάνω λάθος? πιστεύω πως το configuration και το applicationContext τα έχω σωστά....

παρακάτω επισυνάπτω και το application-context

<?xml  version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
	http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

	<!-- Activate Annotations in Beans -->
	<context:annotation-config />
	
	<!-- Scan and Register Beans Under this Package -->
	<context:component-scan base-package="gr.findtheloc" />	
	
	<!-- Configure JPA -->
	<jpa:repositories base-package="gr.findtheloc.repository" />
	
	<!-- Load Configurations from Files -->
	<context:property-placeholder location="classpath:properties/datasource.properties,
		classpath:properties/hibernate.properties"/>
	
	<!-- Hikari Connection Pool Configuration -->
	<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
		<property name="poolName" value="springHikariCP" />
		<property name="connectionTestQuery" value="SELECT 1" />
		<property name="dataSourceClassName" value="${datasource.classname}" />
		<property name="transactionIsolation" value="TRANSACTION_READ_COMMITTED" />					
		<property name="dataSourceProperties">
			<props>
				<prop key="url">${datasource.url}</prop>
				<prop key="user">${datasource.username}</prop>
				<prop key="password">${datasource.password}</prop>				
			</props>
		</property>
	</bean>
	
	<!-- Define Hikari Bean -->
	<bean id="findthelocDataSource" class="com.zaxxer.hikari.HikariDataSource"
		destroy-method="close">
		<constructor-arg ref="hikariConfig" />
	</bean>

	<!-- Create the JPA Entity Manager Factory -->
	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
		<property name="dataSource" ref="findthelocDataSource" />
		<property name="packagesToScan">
			<list>
				<value>gr.findtheloc.model</value>
			</list>
		</property>
		<property name="jpaProperties">
			<props>
				<prop key="hibernate.dialect">${hibernate.dialect}</prop>
				<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>							
				<prop key="hibernate.globally_quoted_identifiers">${hibernate.globally_quoted_identifiers}</prop>
				<prop key="hibernate.hikari.idleTimeout">${hibernate.hikari.idleTimeout}</prop>
				<prop key="hibernate.use_sql_comments">${hibernate.use_sql_comments}</prop>
				<prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
			</props>
		</property>
		<property name="persistenceProvider">
			<bean class="org.hibernate.jpa.HibernatePersistenceProvider" />
		</property>
	</bean>
	<tx:annotation-driven transaction-manager="transactionManager" />
	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
		<property name="entityManagerFactory" ref="entityManagerFactory" />
	</bean>
</beans>

Ευχαριστώ εκ των προτέρων !!!

Δημοσ.

ενας ενας οι απαντησεις παιδιά :P  

 

ας σβηστει το θεμα την βρηκα την λύση εδω και κατι μερες απλα ξεχασα να το αναφερω  :)

Δημοσ.

με το συμπαθειο ρε φιλε αλλά το μήνυμα λάθους είναι ξεκάθαρο, παει να περάσει τιμή null σε required property!

Το λάθος βρίσκεται στο ονομα του angular binding για το password, ng-model="personCtrl.person.pass"

Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε

Πρέπει να είστε μέλος για να αφήσετε σχόλιο

Δημιουργία λογαριασμού

Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!

Δημιουργία νέου λογαριασμού

Σύνδεση

Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.

Συνδεθείτε τώρα
  • Δημιουργία νέου...