Avatar
1
Mathis Favier Beginner
Mathis Favier Beginner
[Easyfox-server] null pointer Exception on user repo while trying to connect
So I watched the <a href="https://www.youtube.com/watch?v=aTZDSiiITBM&amp;list=PLlZavoxtKE1IfKY7ohkLLyv6YkHMkvH6G&amp;index=4">video</a> for the authentication with Ezyfox-server but I got an NullPointerException on UserRepo while I try to log in. I can't figure out why because I triple check my code and the video... <p> </p> <p> Here is my code: </p> <p> </p> <pre> # entity/BullyUser: @Getter @Setter @ToString @EzyCollection public class BullyUser { @EzyId int id; String username; String password; } # repo/BullyUserRepo: @EzyRepository("userRepo") public interface BullyUserRepo extends EzyMongoRepository&lt;Long, BullyUser&gt; { } # service/BullyUserService: public interface BullyUserService { void saveUser(BullyUser user); BullyUser createUser(String username, String password); BullyUser getUser(String username); } # service/impl/BullyUserServiceImpl: @Setter @EzySingleton("userService") public class BullyUserServiceImpl implements BullyUserService { @EzyAutoBind private BullyUserRepo BullyUserRepo; @Override public void saveUser(BullyUser user) { BullyUserRepo.save(user); } @Override public BullyUser createUser(String username, String password) { BullyUser user = new BullyUser(); user.setUsername(username); user.setPassword(password); BullyUserRepo.save(user); return user; } @Override public BullyUser getUser(String username) { return BullyUserRepo.findByField("username", username); } } // [PLUGIN]/controller/UserLoginController @EzySingleton @EzyEventHandler(USER_LOGIN) public class UserLoginController extends EzyAbstractPluginEventController { @EzyAutoBind private WelcomeService welcomeService; @EzyAutoBind private BullyUserService userService; @Override public void handle(EzyPluginContext ctx, EzyUserLoginEvent event) { logger.info("{} login in", welcomeService.welcome(event.getUsername())); String username = event.getUsername(); String password = event.getPassword(); BullyUser user = userService.getUser(username); if (user == null) { logger.info("User {} does not exist, creating new user", username); user = userService.createUser(username, password); userService.saveUser(user); } } } </pre>
Answer
Avatar
2
8bu Beginner
8bu Beginner
[Webpack] Build/Bundle issue - Vue project build cả những files không được import/sử dụng (unused)
Hiện tại mình đang thực hiện optimize build time cho 1 source code dự án đã phình khá to. Các helper module trong dự án đang được export &amp; sử dụng kiểu như này: <pre>// utils/index.ts export * from './helper-a.ts'; export * from './helper-b.ts'; export * from './helper-c.ts'; // components/Button.vue &lt;script lang="ts"&gt; import { HelperA } from '../utils'; &lt;/script&gt; </pre> <p> Nhưng khi build, bundle build ra bao gồm luôn cả helper-b và helper-c (mặc dù không được sử dụng). Mình có đọc vào phần tree shaking của webpack nhưng chưa tìm được cách giải quyết tối ưu nhất ngoài việc manual remove unused hoặc sửa lại cách export/import của toàn bộ source. Anh/chị/em có cách nào giải quyết tốt hơn xin gợi ý giúp mình với ạ. Mình cảm ơn. </p> <p> </p> <hr /> <p> </p> <p> Bổ sung cấu trúc utils &amp; code sample cho helper: </p> <pre>utils/ ┣ browser/ ┃ ┗ clipboard.ts ┣ data/ ┃ ┗ snapshot.ts ┣ date/ ┃ ┣ custom-format.ts ┃ ┣ format.ts ┃ ┣ index.ts ┃ ┣ now.ts ┃ ┗ toTimer.ts ┣ file/ ┃ ┣ file.ts ┃ ┗ image.ts ┣ mapper/ ┃ ┣ paginate.ts ┃ ┗ status-mapper.ts ┣ normalizer/ ┃ ┣ chain_id.normalize.ts ┃ ┣ index.ts ┃ ┣ number.normalize.ts ┃ ┗ path_name.normalize.ts ┣ number/ ┃ ┣ bignumber.ts ┃ ┣ calculation.ts ┃ ┣ comparison.ts ┃ ┣ format.ts ┃ ┣ index.ts ┃ ┗ shift.ts ┣ object/ ┃ ┣ getKeys.ts ┃ ┗ index.ts ┣ system/ ┃ ┣ async.ts ┃ ┣ promise.ts ┃ ┗ reTryCatch.ts ┣ token/ ┃ ┣ token-address.ts ┃ ┣ token-data-display.ts ┃ ┣ token-data.ts ┃ ┗ token-icon.ts ┣ ... ┣ campaign.ts ┣ contract.ts ┣ copy.ts ┣ index.ts ┣ misc.ts ┣ notification.ts ┣ promise.ts ┣ random.ts ┣ ref.ts ┣ string.ts ┣ viewport.ts ┗ string.ts</pre> <pre>----------------------------------------------- // utils/normalizer/path_name.normalize.ts export const normalizeFileName = (path: string) =&gt; {   return (path.split('/').pop() as string).replace(/\\.\\w+$/, '') as string; }; // utils/normalizer/index.ts export * from './chain_id.normalize'; export * from './path_name.normalize'; export * from './number.normalize'; // utils/index.ts export * from './browser/clipboard'; export * from './copy'; export * from './data/snapshot'; export * from './date'; export * from './file/file'; export * from './file/image'; export * from './mapper/paginate'; export * from './misc'; export * from './normalizer'; export * from './notification'; export * from './number'; export * from './object'; export * from './promise'; export * from './ref'; export * from './string'; export * from './system/async'; export * from './system/promise'; export * from './system/reTryCatch'; export * from './validate'; ....</pre>
Answer